[PATCH v1 1/1] travis-ci: Fix "ResourceWarning: unclosed file"

Cristian Ciocaltea cristian.ciocaltea at gmail.com
Mon Dec 30 00:41:09 CET 2019


This patch gets rid of the warning messages like:

uboot-test-hooks/py/travis-ci/travis_tftp.py:43: ResourceWarning:
unclosed file <_io.BufferedReader name='.bm-work/qemu_arm/u-boot.bin'>

Signed-off-by: Cristian Ciocaltea <cristian.ciocaltea at iquestgroup.com>
---
 py/travis-ci/travis_tftp.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/py/travis-ci/travis_tftp.py b/py/travis-ci/travis_tftp.py
index 4ea5c06..3e1f11d 100644
--- a/py/travis-ci/travis_tftp.py
+++ b/py/travis-ci/travis_tftp.py
@@ -20,8 +20,11 @@ def file2env(file_name, addr=None):
     ret = {
         "fn": file_name,
         "size": os.path.getsize(file_full),
-        "crc32": hex(binascii.crc32(open(file_full, 'rb').read()) & 0xffffffff)[2:],
     }
+
+    with open(file_full, 'rb') as fd:
+        ret["crc32"] = hex(binascii.crc32(fd.read()) & 0xffffffff)[2:]
+
     if addr is not None:
         ret['addr'] = addr
 
-- 
2.17.1



More information about the U-Boot mailing list