Skip to contentSkip to conversation

utils: lock_timeout_nocheck() ensure `l` is initialized

PATCH New Mark Asselstine 1 participant 1 message Apr 11, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils: lock_timeout_nocheck() ensure `l` is initialized

lock_timeout_nocheck() can be interrupted immediately after enterring the try-block and prior to initializing 'l', for example with a ctrl-C, the code in finally will still be run and the 'if l' will fail. Initialize 'l' as False to avoid this possiblity.

---
 lib/bb/utils.py | 1 +
 1 file changed, 1 insertion(+)
lib/bb/utils.py +1 -0
index 5486f9599..a1e093925 100644
@@ -1898,6 +1898,7 @@ def lock_timeout(lock):
 # A version of lock_timeout without the check that the lock was locked and a shorter timeout
 @contextmanager
 def lock_timeout_nocheck(lock):
+    l = False
     try:
         s = signal.pthread_sigmask(signal.SIG_BLOCK, signal.valid_signals())
         l = lock.acquire(timeout=10)
Signature · 1 line
2.39.5