Python Lock / Mutex minimales Beispiel (threading.Lock)

Dieses minimale Beispiel erstellt ein threading.Lock und sperrt es mit einer with-Anweisung. Dies ist die einfachste Methode zur Verwendung eines Lock.

threading_lock_example.py
from threading import Lock

lock = Lock()

with lock:
    print("Holding the lock!")

Check out similar posts by category: Python