[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/10] python/machine: Disable pylint warning for open() in _pre_
From: |
John Snow |
Subject: |
[PATCH 05/10] python/machine: Disable pylint warning for open() in _pre_launch |
Date: |
Wed, 12 May 2021 17:46:37 -0400 |
Shift the open() call later so that the pylint pragma applies *only* to
that one open() call. Add a note that suggests why this is safe: the
resource is unconditionally cleaned up in _post_shutdown().
_post_shutdown is called after failed launches (see launch()), and
unconditionally after every call to shutdown(), and therefore also on
__exit__.
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/machine.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index c13ff9b32bf..8f86303b48f 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -308,7 +308,6 @@ def _pre_launch(self) -> None:
self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-",
dir=self._test_dir)
self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log")
- self._qemu_log_file = open(self._qemu_log_path, 'wb')
if self._console_set:
self._remove_files.append(self._console_address)
@@ -323,6 +322,11 @@ def _pre_launch(self) -> None:
nickname=self._name
)
+ # NOTE: Make sure any opened resources are *definitely* freed in
+ # _post_shutdown()!
+ # pylint: disable=consider-using-with
+ self._qemu_log_file = open(self._qemu_log_path, 'wb')
+
def _post_launch(self) -> None:
if self._qmp_connection:
self._qmp.accept()
--
2.30.2
- [PATCH 04/10] python/console_socket: Add a pylint ignore, (continued)
- [PATCH 04/10] python/console_socket: Add a pylint ignore, John Snow, 2021/05/12
- [PATCH 08/10] iotests: use 'with open()' where applicable, John Snow, 2021/05/12
- [PATCH 06/10] python/machine: disable warning for Popen in _launch(), John Snow, 2021/05/12
- [PATCH 09/10] iotests: silence spurious consider-using-with warnings, John Snow, 2021/05/12
- [PATCH 07/10] iotests: use subprocess.run where possible, John Snow, 2021/05/12
- [PATCH 02/10] python/machine: use subprocess.DEVNULL instead of open(os.path.devnull), John Snow, 2021/05/12
- [PATCH 10/10] iotests: ensure that QemuIoInteractive definitely closes, John Snow, 2021/05/12
- [PATCH 05/10] python/machine: Disable pylint warning for open() in _pre_launch,
John Snow <=
- Re: [PATCH 00/10] Python: delint iotests, machine.py and console_socket.py, John Snow, 2021/05/17