[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH RFC 03/32] python//machine.py: remove bare except
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH RFC 03/32] python//machine.py: remove bare except |
Date: |
Tue, 26 May 2020 17:09:18 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 5/14/20 7:53 AM, John Snow wrote:
> Catch only the timeout error; if there are other problems, allow the
> stack trace to be visible.
>
> Signed-off-by: John Snow <address@hidden>
> ---
> python/qemu/lib/machine.py | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py
> index b9a98e2c86..e3ea523571 100644
> --- a/python/qemu/lib/machine.py
> +++ b/python/qemu/lib/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()
>
>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
- Re: [PATCH RFC 01/32] python/qemu: create qemu.lib module, (continued)
[PATCH RFC 02/32] scripts/qmp: Fix shebang and imports, John Snow, 2020/05/14
[PATCH RFC 03/32] python//machine.py: remove bare except, John Snow, 2020/05/14
Re: [PATCH RFC 03/32] python//machine.py: remove bare except,
Philippe Mathieu-Daudé <=
[PATCH RFC 04/32] python/qemu/lib: delint, add pylintrc, John Snow, 2020/05/14
[PATCH RFC 05/32] python/qemu/lib: delint; add flake8 config, John Snow, 2020/05/14
[PATCH RFC 06/32] python/qemu: formalize as package, John Snow, 2020/05/14
[PATCH RFC 07/32] python/qemu: add README.rst, John Snow, 2020/05/14
[PATCH RFC 10/32] python/qemu: Add flake8 to Pipfile, John Snow, 2020/05/14
[PATCH RFC 09/32] python/qemu: add pylint to Pipfile, John Snow, 2020/05/14