summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2020-03-11 18:28:44 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-03-12 23:03:06 +0000
commitb3f3779adf63c0d970462a558a6205da1d30c0ed (patch)
tree0fe48979e6936f5f3cb321b43b09eed4dbb7b60b
parente22565968828c86983162e67f52ebb106242ca76 (diff)
downloadbitbake-b3f3779adf63c0d970462a558a6205da1d30c0ed.tar.gz
knotty: Add logging cleanup
Adds code to close all loggers when bitbake exits. This prevents unclosed file ResourceWarnings. A form of this closing existed previously, but was removed in the new logging code. Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/msg.py11
-rw-r--r--lib/bb/ui/knotty.py2
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/bb/msg.py b/lib/bb/msg.py
index 6259af037..05645739d 100644
--- a/lib/bb/msg.py
+++ b/lib/bb/msg.py
@@ -320,3 +320,14 @@ def setLoggingConfig(defaultconfig, userconfigfile=None):
# TODO: I don't think that setting the global log level should be necessary
#if newlevel < bb.msg.loggerDefaultLogLevel:
# bb.msg.loggerDefaultLogLevel = newlevel
+
+def cleanupLogging():
+ # Iterate through all the handlers and close them if possible. Fixes
+ # 'Unclosed resource' warnings when bitbake exits, see
+ # https://bugs.python.org/issue23010
+ handlers = set()
+ for logger_iter in logging.Logger.manager.loggerDict.keys():
+ handlers.update(logging.getLogger(logger_iter).handlers)
+
+ for h in handlers:
+ h.close()
diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 386f27876..695108a64 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -823,4 +823,6 @@ def main(server, eventHandler, params, tf = TerminalFilter):
if e.errno == errno.EPIPE:
pass
+ bb.msg.cleanupLogging()
+
return return_value