From 7278f3f786b52b64fa3ecd7eee7b9f74428bfaf3 Mon Sep 17 00:00:00 2001 From: Chris Laplante via bitbake-devel Date: Tue, 10 Dec 2019 14:10:20 -0500 Subject: bitbake: bb.utils.fileslocked: don't leak files if yield throws Discovered with a recipe under devtool. The ${S}/singletask.lock file (added by externalsrc.bbclass) was leaked, giving a warning like: WARNING: +git999-r0 do_populate_lic: /home/laplante/yocto/sources/poky/bitbake/lib/bb/build.py:582: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/laplante/yocto/build/workspace/sources//singletask.lock' mode='a+' encoding='UTF-8'> exec_func(task, localdata) (Bitbake rev: 81829ab28afae08e02f4a758ec063fc0d90579ea) Signed-off-by: Chris Laplante Signed-off-by: Richard Purdie (cherry picked from commit 6beddf6214e22b4002626761031a9e9d34fb04db) Signed-off-by: Richard Purdie --- bitbake/lib/bb/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'bitbake') diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 8d40bcdf83..d65265c461 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py @@ -428,10 +428,11 @@ def fileslocked(files): for lockfile in files: locks.append(bb.utils.lockfile(lockfile)) - yield - - for lock in locks: - bb.utils.unlockfile(lock) + try: + yield + finally: + for lock in locks: + bb.utils.unlockfile(lock) @contextmanager def timeout(seconds): -- cgit v1.2.3-54-g00ecf