[PATCH 08/14] functional: ensure log handlers are closed

Daniel P. Berrangé posted 14 patches 4 months ago
Maintainers: John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Elena Ufimtseva <elena.ufimtseva@oracle.com>, Jagannathan Raman <jag.raman@oracle.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
[PATCH 08/14] functional: ensure log handlers are closed
Posted by Daniel P. Berrangé 4 months ago
This avoids a resource leak warning from python when the
log handler is garbage collected.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/functional/qemu_test/testcase.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
index 2082c6fce4..71c7160adc 100644
--- a/tests/functional/qemu_test/testcase.py
+++ b/tests/functional/qemu_test/testcase.py
@@ -232,6 +232,7 @@ def tearDown(self):
             self.socketdir = None
         self.machinelog.removeHandler(self._log_fh)
         self.log.removeHandler(self._log_fh)
+        self._log_fh.close()
 
     def main():
         path = os.path.basename(sys.argv[0])[:-3]
@@ -399,4 +400,5 @@ def tearDown(self):
         for vm in self._vms.values():
             vm.shutdown()
         logging.getLogger('console').removeHandler(self._console_log_fh)
+        self._console_log_fh.close()
         super().tearDown()
-- 
2.49.0


Re: [PATCH 08/14] functional: ensure log handlers are closed
Posted by Thomas Huth 4 months ago
On 15/07/2025 16.30, Daniel P. Berrangé wrote:
> This avoids a resource leak warning from python when the
> log handler is garbage collected.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/functional/qemu_test/testcase.py | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index 2082c6fce4..71c7160adc 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -232,6 +232,7 @@ def tearDown(self):
>               self.socketdir = None
>           self.machinelog.removeHandler(self._log_fh)
>           self.log.removeHandler(self._log_fh)
> +        self._log_fh.close()
>   
>       def main():
>           path = os.path.basename(sys.argv[0])[:-3]
> @@ -399,4 +400,5 @@ def tearDown(self):
>           for vm in self._vms.values():
>               vm.shutdown()
>           logging.getLogger('console').removeHandler(self._console_log_fh)
> +        self._console_log_fh.close()
>           super().tearDown()

Reviewed-by: Thomas Huth <thuth@redhat.com>