Python--day41--条件

1,条件

#锁

#acquire release
#一个条件被创建之初 默认有一个False状态
#False状态 会影响wait一直处于等待状态
#notify(int数据类型) 造钥匙

代码示例:条件.py

 1 from threading import Condition
 2 from threading import Thread
 3 def func(con,i):
 4     con.acquire()
 5     con.wait()  #等钥匙
 6     print('在第%s个循环里'%i)
 7     con.release()
 8 con = Condition()
 9 for i in range(10):
10     Thread(target=func,args=(con,i)).start()
11 while True:
12     num = int(input('>>>'))
13     con.acquire()
14     con.notify(num) #造钥匙
15     con.release()

运行结果:

2,notify造钥匙的过程:

原文地址:https://www.cnblogs.com/xudj/p/10346932.html