Merge pull request #4988 from blueyed/logging-close

logging: close log_file_handler
This commit is contained in:
Daniel Hahler 2019-03-26 19:57:57 +01:00 committed by GitHub
commit 49f36bb028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1 @@
Close logging's file handler explicitly when the session finishes.

View File

@ -577,8 +577,15 @@ class LoggingPlugin(object):
if self.log_cli_handler:
self.log_cli_handler.set_when("sessionfinish")
if self.log_file_handler is not None:
with catching_logs(self.log_file_handler, level=self.log_file_level):
yield
try:
with catching_logs(
self.log_file_handler, level=self.log_file_level
):
yield
finally:
# Close the FileHandler explicitly.
# (logging.shutdown might have lost the weakref?!)
self.log_file_handler.close()
else:
yield