python with lock
2018-03-01 本文已影响0人
橙姜
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.