import threading
from time import sleep
import rwlock # pip3 install rwlock
l = rwlock.RWLock()
class myThread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
#l.writer_lock.acquire() # 写锁
l.reader_lock.acquire() # 读锁
print ("Starting ")
sleep(5)
print ("Exiting ")
#l.writer_lock.release()
l.reader_lock.release()
# Create new threads
thread1 = myThread()
thread2 = myThread()
thread1.start()
thread2.start()
Python读写锁
最新推荐文章于 2024-03-13 10:40:25 发布