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

Cristian Ciocaltea cristian.ciocaltea at gmail.com
Mon Dec 30 12:49:49 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 gmail.com>
---
Changes in v2:
* The warning line number in the comment relies on Heinrich Schuchardt's
  work 'travis-ci: provide env__efi_fit_tftp_file', but my initial patch
  was based on the master version. Even though it is still applicable,
  to avoid any confusion, I rebased it on Heinrich's latest patch (v2):
  
  https://lists.denx.de/pipermail/u-boot/2019-December/395029.html

 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 884823c..f9a44aa 100644
--- a/py/travis-ci/travis_tftp.py
+++ b/py/travis-ci/travis_tftp.py
@@ -40,8 +40,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