bitbake: 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.

(Bitbake rev: b3f3779adf63c0d970462a558a6205da1d30c0ed)

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Watt
2020-03-11 18:28:44 -05:00
committed by Richard Purdie
parent 03e35419af
commit c8b2694cd4
2 changed files with 13 additions and 0 deletions

View File

@@ -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()

View File

@@ -823,4 +823,6 @@ def main(server, eventHandler, params, tf = TerminalFilter):
if e.errno == errno.EPIPE:
pass
bb.msg.cleanupLogging()
return return_value