条件锁例题
from threading import Thread
import threading
def work1(cond):
# for i in range(1,53,2)
data = zip(range(1, 53, 2), range(2, 53, 2))
for i in data:
with cond:
print(*i, sep="",end="")
cond.notify()
cond.wait()
def work2(cond):
data = [chr(i) for i in range(ord('A'), ord('Z')+1)]
for i in data:
with cond:
cond.wait()
print(i,end=" ")
cond.notify()
if __name__ == "__main__":
cond=threading.Condition()
tar1=threading.Thread(target=work1,args=(cond,))
tar2=threading.Thread(target=work2,args=(cond,))
tar2.start()
tar1.start()