Leaked concurrency handle (ARCH2085)
Key python.performance.leaked-concurrency-handle · Severity warning · Category performance
A lock acquired without a guaranteed release is never freed if an error occurs, causing deadlock. Bound its lifetime with with.
Incorrect
Section titled “Incorrect”import threading
lock = threading.Lock()
def increment(counter): lock.acquire() counter.value += 1 lock.release()Correct
Section titled “Correct”import threading
lock = threading.Lock()
def increment(counter): with lock: counter.value += 1Acquire locks with with lock:, join threads, or wrap handles in a context manager.