Skip to contentSkip to conversation

COW: Fix StopIteration warning

PATCH New Richard Purdie 1 participant 2 messages Sep 22, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 COW: Fix StopIteration warning

Fix the warning:

WARNING: lib/bb/data_smart.py:235: DeprecationWarning: generator 'COWDictMeta.iter' raised StopIteration
for k, v in self.variables.iteritems():

by using return from the generator, not raising StopIteration.

---
 lib/bb/COW.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/COW.py +1 -1
index bec6208096..7817473ab8 100644
@@ -150,7 +150,7 @@ class COWDictMeta(COWMeta):
                 yield value
             if type == "items":
                 yield (key, value)
-        raise StopIteration()
+        return
 
     def iterkeys(cls):
         return cls.iter("keys")
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 daemonize/build: Clean up /dev/null fd handling

At the end of bitbake selftest we see:

sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r+' encoding='UTF-8'>

Clean up the /dev/null handling to drop the unused entry in build.by and ensure the other open() calls are cleaned up.

NULL was unused since http://git.yoctoproject.org/cgit.cgi/poky/commit/bitbake/lib/bb/build.py?id=4a081b5a52e3d27da8d4b062f3fda292e8d8fb0a
back in 2012.

---
 lib/bb/build.py     | 7 ++-----
 lib/bb/daemonize.py | 4 ++--
 2 files changed, 4 insertions(+), 7 deletions(-)
lib/bb/build.py +2 -5
index c79354b3f1..3e2a94edb1 100644
@@ -41,8 +41,6 @@ from bb import data, event, utils
 bblogger = logging.getLogger('BitBake')
 logger = logging.getLogger('BitBake.Build')
 
-NULL = open(os.devnull, 'r+')
-
 __mtime_cache = {}
 
 def cached_mtime_noerror(f):
@@ -533,7 +531,6 @@ def _exec_task(fn, task, d, quieterr):
                 self.triggered = True
 
     # Handle logfiles
-    si = open('/dev/null', 'r')
     try:
         bb.utils.mkdirhier(os.path.dirname(logfn))
         logfile = open(logfn, 'w')
@@ -547,7 +544,8 @@ def _exec_task(fn, task, d, quieterr):
     ose = [os.dup(sys.stderr.fileno()), sys.stderr.fileno()]
 
     # Replace those fds with our own
-    os.dup2(si.fileno(), osi[1])
+    with open('/dev/null', 'r') as si:
+        os.dup2(si.fileno(), osi[1])
     os.dup2(logfile.fileno(), oso[1])
     os.dup2(logfile.fileno(), ose[1])
 
@@ -608,7 +606,6 @@ def _exec_task(fn, task, d, quieterr):
         os.close(osi[0])
         os.close(oso[0])
         os.close(ose[0])
-        si.close()
 
         logfile.close()
         if os.path.exists(logfn) and os.path.getsize(logfn) == 0:
lib/bb/daemonize.py +2 -2
index 613fb35536..c937675eb6 100644
@@ -65,8 +65,8 @@ def createDaemon(function, logfile):
     # The second child.
 
     # Replace standard fds with our own
-    si = open('/dev/null', 'r')
-    os.dup2(si.fileno(), sys.stdin.fileno())
+    with open('/dev/null', 'r') as si:
+        os.dup2(si.fileno(), sys.stdin.fileno())
 
     try:
         so = open(logfile, 'a+')
Signature · 1 line
2.17.1