Aller au contenu

Leaked concurrency handle (ARCH2085)

Ce contenu n’est pas encore disponible dans votre langue.

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.

import threading
lock = threading.Lock()
def increment(counter):
lock.acquire()
counter.value += 1
lock.release()
import threading
lock = threading.Lock()
def increment(counter):
with lock:
counter.value += 1

Acquire locks with with lock:, join threads, or wrap handles in a context manager.