event: prevent unclosed file warning in print_ui_queue
PATCH 1/1 event: prevent unclosed file warning in print_ui_queue
Use logger.addHandler(), rather than assigning an array of Handlers to the loggers handlers property directly, to avoid a warning from Python 3 about unclosed files:
$ bitbake Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information. WARNING: /home/joshuagl/Projects/poky/bitbake/lib/bb/event.py:143: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/joshuagl/Projects/poky/build/tmp/log/cooker/qemux86/20161004094928.log' mode='a' encoding='UTF-8'> logger.handlers = [stdout]
Signed-off-by Joshua Lock <[email protected]>
--- lib/bb/event.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
lib/bb/event.py +3 -3
@@ -131,16 +131,16 @@ def print_ui_queue(): if isinstance(event, logging.LogRecord): if event.levelno > logging.DEBUG: if event.levelno >= logging.WARNING: - logger.handlers = [stderr] + logger.addHandler(stderr) else: - logger.handlers = [stdout] + logger.addHandler(stdout) logger.handle(event) msgprint = True if msgprint: return # Nope, so just print all of the messages we have (including debug messages) - logger.handlers = [stdout] + logger.addHandler(stdout) for event in ui_queue: if isinstance(event, logging.LogRecord): logger.handle(event)
Signature · 1 line
2.7.4
Quoted 13 lines · Joshua Lock
Use
logger.addHandler(), rather than assigning an array of Handlers to the loggers handlers property directly, to avoid a warning from Python 3 about unclosed files:$ bitbake Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information. WARNING: /home/joshuagl/Projects/poky/bitbake/lib/bb/event.py:143: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/joshuagl/Projects/poky/build/tmp/log/cooker/qemux86/20161004094928.log' mode='a' encoding='UTF-8'> logger.handlers = [stdout]
Quoted 2 lines
Signed-off-by Joshua Lock <[email protected]>
There are valid cases to do an assignment, or at least clear out the existing handlers via another means. We probably assigned there to ensure it didn’t try to do anything else with the events other than dump them to the output stream. Probably not an issue most of the time, in this case, but worth noting. Good catch on this.
Signature · 5 lines
Christopher Larson clarson at kergoth dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics