for example:
import threading
lock = threading.Lock()
with lock:
some code that throws an exception
This is assuming that code that throws an exception isn't wrapped in a try except block.
The whole point of using your lock as a context manager (with lock:
) is for Python to notify that lock object when an exception occurs.
So yes, the lock will unlock itself when an exception occurs because the with
statement ensures it is notified of an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With