116-python-条件

"""
Condition 条件:
# 每次造的钥匙是一次性的
# acquire release
# notify(int数据类型) # 造钥匙
"""

from threading import Condition,Thread



def fn(con,i):
    con.acquire()   # 拿钥匙
    con.wait()  # 等钥匙
    print('在第%s个循环中'%i)
    con.release()   # 还钥匙

con = Condition()
for i in range(10):
    Thread(target=fn, args=(con,i)).start()

while True:
    num = int(input('>>>'))
    con.acquire()
    con.notify(num) # 造钥匙
    con.release()

  













posted @ 2018-12-15 17:23  _Q  阅读(116)  评论(0编辑  收藏  举报