Catch only the timeout error; if there are other problems, allow the stack trace to be visible.
Signed-off-by: John Snow <js...@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <phi...@redhat.com> --- python/qemu/machine.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index b9a98e2c862..e3ea5235713 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -342,7 +342,26 @@ def wait(self): self._load_io_log() self._post_shutdown() - def shutdown(self, has_quit=False): + def _issue_shutdown(self, has_quit: bool = False) -> None: + """ + Shutdown the VM. + """ + if not self.is_running(): + return + + if self._qmp is not None: + if not has_quit: + self._qmp.cmd('quit') + self._qmp.close() + + try: + self._popen.wait(timeout=3) + except subprocess.TimeoutExpired: + self._popen.kill() + + self._popen.wait() + + def shutdown(self, has_quit: bool = False) -> None: """ Terminate the VM and clean up """ @@ -353,17 +372,7 @@ def shutdown(self, has_quit=False): self._console_socket.close() self._console_socket = None - if self.is_running(): - if self._qmp: - try: - if not has_quit: - self._qmp.cmd('quit') - self._qmp.close() - self._popen.wait(timeout=3) - except: - self._popen.kill() - self._popen.wait() - + self._issue_shutdown(has_quit) self._load_io_log() self._post_shutdown() -- 2.21.3