From e3ef868d7d1c5c03d1d65d6917314573080c46a9 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Tue, 17 May 2022 18:05:50 -0300 Subject: [PATCH] Attempt to fix QEMU hangs by not using the popen/communicate flow when no monitor command is requested --- biostools/extractors.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/biostools/extractors.py b/biostools/extractors.py index d1af992..66c9554 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -2562,21 +2562,24 @@ class VMExtractor(ArchiveExtractor): # Run QEMU. self.debug_print('Running QEMU with args:', args) try: - proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=self._devnull, stderr=subprocess.STDOUT) + if monitor_cmd and monitor_flag_file: + proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=self._devnull, stderr=subprocess.STDOUT) - # Wait for flag file if one was specified. - if monitor_flag_file: - spins = 0 - while not os.path.exists(monitor_flag_file) and spins < 60: - time.sleep(1) - spins += 1 - if spins < 60: - self.debug_print('Monitor flag file found') - else: - self.debug_print('Monitor flag file timed out') + # Wait for flag file if one was specified. + if monitor_flag_file: + spins = 0 + while not os.path.exists(monitor_flag_file) and spins < 60: + time.sleep(1) + spins += 1 + if spins < 60: + self.debug_print('Monitor flag file found') + else: + self.debug_print('Monitor flag file timed out') - # Send monitor command if one was specified, and wait for the QEMU process. - proc.communicate(input=monitor_cmd, timeout=60) + # Send monitor command if one was specified, and wait for the QEMU process. + proc.communicate(input=monitor_cmd, timeout=60) + else: + subprocess.run(args, input=monitor_cmd, timeout=60, stdout=self._devnull, stderr=subprocess.STDOUT) except: self.debug_print('Running QEMU failed (timed out?)')