https://docs.python.org/2.5/whatsnew/pep-343.html
The threading module's locks and condition variables also support the 'with' statement:
lock = threading.Lock()
with lock:
# Critical section of code
...
The lock is acquired before the block is executed and always released once the block is complete.
网友评论