标签:elf time() name import time sleep threading def 死锁
import threading
import time
lock =threading.RLock()
class Mythread(threading.Thread):
def __init__(self,name):
super(Mythread,self).__init__()
self.name = name
def doA(self):
lock.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lock.acquire()
print(self.name, "gotlockB", time.ctime())
lock.release()
lock.release()
def doB(self):
lock.acquire()
print(self.name, "gotlockA", time.ctime())
time.sleep(3)
lock.acquire()
print(self.name, "gotlockB", time.ctime())
lock.release()
lock.release()
def run(self):
self.doA()
self.doB()
if __name__ == ‘__main__‘:
t1 = Mythread("thread-1")
t2 = Mythread("thread-2")
t1.start()
t2.start()
标签:elf time() name import time sleep threading def 死锁
原文地址:https://www.cnblogs.com/knowlearner/p/10404321.html