from threading import Condition,Thread import time def func(con,i): con.acquire() con.wait() print("第%s个线程执行了" % i) con.release() con = Condition() # 先实例化一个对象 for i in range(10): # 创建10个子线程 t = Thread(target=func,args=(con,i)) t.start() while True: num = int(input(">>>:")) con.acquire() con.notify(num) # 给wait发送int个信号,会传递给int个wait,让int个线程正常执行 con.release() time.sleep(1)