All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] event: prevent unclosed file warning in print_ui_queue
@ 2016-10-04 10:03 Joshua Lock
  2016-10-04 15:00 ` Christopher Larson
  0 siblings, 1 reply; 2+ messages in thread
From: Joshua Lock @ 2016-10-04 10:03 UTC (permalink / raw)
  To: bitbake-devel

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 <joshua.g.lock@intel.com>
---
 lib/bb/event.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/bb/event.py b/lib/bb/event.py
index 42745e2..e35b932 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -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)
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] event: prevent unclosed file warning in print_ui_queue
  2016-10-04 10:03 [PATCH] event: prevent unclosed file warning in print_ui_queue Joshua Lock
@ 2016-10-04 15:00 ` Christopher Larson
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Larson @ 2016-10-04 15:00 UTC (permalink / raw)
  To: Joshua Lock; +Cc: bitbake-devel

[-- Attachment #1: Type: text/plain, Size: 1213 bytes --]

On Tue, Oct 4, 2016 at 3:03 AM, Joshua Lock <joshua.g.lock@intel.com> wrote:

> 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 <joshua.g.lock@intel.com>
>

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.
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 1876 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-04 15:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-04 10:03 [PATCH] event: prevent unclosed file warning in print_ui_queue Joshua Lock
2016-10-04 15:00 ` Christopher Larson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.