[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'returncode
From: |
Amador Pahim |
Subject: |
[Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'returncode' |
Date: |
Fri, 18 Aug 2017 19:05:19 +0200 |
The 'returncode' Popen attribute is not guaranteed to be updated. It
actually depends on a call to either poll(), wait() or communicate().
On the other hand, poll() will: "Check if child process has terminated.
Set and return returncode attribute."
Let's use the poll() to check whether the process is running and also
to get the updated process exit code, when the process is finished.
As consequence, the shutdown() calls to self._load_io_log()
self._post_shutdown() are now always executed to make sure we cleanup
even if VM is not running when the shutdown() is called.
Signed-off-by: Amador Pahim <address@hidden>
---
scripts/qemu.py | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/scripts/qemu.py b/scripts/qemu.py
index 51545f7f97..774f971f69 100644
--- a/scripts/qemu.py
+++ b/scripts/qemu.py
@@ -98,12 +98,12 @@ class QEMUMachine(object):
raise
def is_running(self):
- return self._popen is not None and self._popen.returncode is None
+ return self._popen is not None and self._popen.poll() is None
def exitcode(self):
if self._popen is None:
return None
- return self._popen.returncode
+ return self._popen.poll()
def get_pid(self):
if not self.is_running():
@@ -111,8 +111,15 @@ class QEMUMachine(object):
return self._popen.pid
def _load_io_log(self):
- with open(self._qemu_log_path, "r") as fh:
- self._iolog = fh.read()
+ '''
+ Load the Qemu log file content (if available) into the proper
+ instance variable
+ '''
+ try:
+ with open(self._qemu_log_path, "r") as fh:
+ self._iolog = fh.read()
+ except IOError:
+ pass
def _base_args(self):
if isinstance(self._monitor_address, tuple):
@@ -168,8 +175,8 @@ class QEMUMachine(object):
if exitcode < 0:
LOG.debug('qemu received signal %i: %s', -exitcode,
' '.join(self._args))
- self._load_io_log()
- self._post_shutdown()
+ self._load_io_log()
+ self._post_shutdown()
underscore_to_dash = string.maketrans('_', '-')
def qmp(self, cmd, conv_keys=True, **args):
--
2.13.5
- Re: [Qemu-devel] [PATCH v7 07/11] qemu.py: include debug information on launch error, (continued)
[Qemu-devel] [PATCH v7 05/11] qemu.py: cleanup redundant calls in launch(), Amador Pahim, 2017/08/18
[Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'returncode',
Amador Pahim <=
[Qemu-devel] [PATCH v7 11/11] qemu.py: refactor launch(), Amador Pahim, 2017/08/18
[Qemu-devel] [PATCH v7 08/11] qemu.py: make sure we only remove files we create, Amador Pahim, 2017/08/18
[Qemu-devel] [PATCH v7 09/11] qemu.py: launch vm only if it's not running, Amador Pahim, 2017/08/18
[Qemu-devel] [PATCH v7 01/11] qemu.py: fix is_running() return before first launch(), Amador Pahim, 2017/08/18
[Qemu-devel] [PATCH v7 03/11] qemu.py: use os.path.null instead of /dev/null, Amador Pahim, 2017/08/18
Re: [Qemu-devel] [PATCH v7 00/11] scripts/qemu.py fixes and cleanups, Eduardo Habkost, 2017/08/31