[bitbake-devel] [PATCH v2] lib/bb/siggen.py: Prevent ResourceWarning exceptions

Mike Looijmans mike.looijmans at topic.nl
Tue Aug 23 06:51:45 UTC 2016


Add a "with" statement to explicitly close files. This prevents hundreds of
"ResourceWarning: unclosed file" outputs.

Signed-off-by: Mike Looijmans <mike.looijmans at topic.nl>
---
v2: Smaller object scope. Wrapped both open() calls.

 lib/bb/siggen.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py
index db3daef..1b3f205 100644
--- a/lib/bb/siggen.py
+++ b/lib/bb/siggen.py
@@ -363,10 +363,10 @@ def clean_basepaths_list(a):
 def compare_sigfiles(a, b, recursecb = None):
     output = []
 
-    p1 = pickle.Unpickler(open(a, "rb"))
-    a_data = p1.load()
-    p2 = pickle.Unpickler(open(b, "rb"))
-    b_data = p2.load()
+    with open(a, "rb") as file_a:
+        a_data = pickle.Unpickler(file_a).load()
+    with open(b, "rb") as file_b:
+        b_data = pickle.Unpickler(file_b).load()
 
     def dict_diff(a, b, whitelist=set()):
         sa = set(a.keys())
@@ -563,8 +563,8 @@ def calc_taskhash(sigdata):
 def dump_sigfile(a):
     output = []
 
-    p1 = pickle.Unpickler(open(a, "rb"))
-    a_data = p1.load()
+    with open(a, "rb") as fa:
+        a_data = pickle.Unpickler(fa).load()
 
     output.append("basewhitelist: %s" % (a_data['basewhitelist']))
 
-- 
1.9.1




More information about the bitbake-devel mailing list