[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 05/31] python/machine: Disable pylint warning for open() in _p
From: |
John Snow |
Subject: |
[PATCH v7 05/31] python/machine: Disable pylint warning for open() in _pre_launch |
Date: |
Tue, 25 May 2021 20:24:28 -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>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Message-id: 20210517184808.3562549-6-jsnow@redhat.com
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 04e005f3811..c66bc6a9c69 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -306,7 +306,6 @@ def _base_args(self) -> List[str]:
def _pre_launch(self) -> None:
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)
@@ -321,6 +320,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.31.1
- [PATCH v7 00/31] python: create installable package, John Snow, 2021/05/25
- [PATCH v7 02/31] python/machine: use subprocess.DEVNULL instead of open(os.path.devnull), John Snow, 2021/05/25
- [PATCH v7 01/31] python/console_socket: avoid one-letter variable, John Snow, 2021/05/25
- [PATCH v7 03/31] python/machine: use subprocess.run instead of subprocess.Popen, John Snow, 2021/05/25
- [PATCH v7 04/31] python/console_socket: Add a pylint ignore, John Snow, 2021/05/25
- [PATCH v7 06/31] python/machine: disable warning for Popen in _launch(), John Snow, 2021/05/25
- [PATCH v7 05/31] python/machine: Disable pylint warning for open() in _pre_launch,
John Snow <=
- [PATCH v7 08/31] iotests/297: add --namespace-packages to mypy arguments, John Snow, 2021/05/25
- [PATCH v7 07/31] python/machine: Trim line length to below 80 chars, John Snow, 2021/05/25
- [PATCH v7 09/31] python: create qemu packages, John Snow, 2021/05/25
- [PATCH v7 13/31] python: add MANIFEST.in, John Snow, 2021/05/25