Python中threading.RLock的使用

301次阅读
没有评论

Python中threading.RLock的使用

Python threading.RLock和Lock的不同

(1)同一个线程可以对RLock请求多次,且RLock必须是本线程;

(2)如果用lock = threading.Lock(),则自动构成死锁,因为Lock只能被请求一次,所以第二次会一直等待下去。

Python threading.RLock实例

import threading
lock = threading.RLock()
def f():  
with lock:    
g()    
h()
def g():  
with lock:    
h()    
do_something1()
def h():  
with lock:    
do_something2()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-04-30发表,共计308字。
新手QQ群:570568346,欢迎进群讨论 Python51学习