python多线程with方式加锁
"""标签:加锁,temp,python,lock,Lock,多线程 From: https://www.cnblogs.com/CJTARRR/p/17764083.html
python Treading中的Lock模块提供了加锁和释放锁的方法,分别是acquire()和release().
这两个方法可以搭配python的with语句使用.
"""
# 示例
from threading import Lock
temp_lock = Lock()
with temp_lock:
print(temp_lock)
# 输出是 <locked _thread.lock object at 0x10e304870> 说明temp_lock上锁了
print(temp_lock)
# 输出是<unlocked _thread.lock object at 0x10e304870> 说明temp_lock被释放了