条件、事件、信号量本质上都是锁,不常用
""" 常用方法: obj,acquire() Obj.release() obj.wait(),创建是阻塞状态,等待obj.notify()并且前后要有obj.acquire()和obj.release() obj.notify(num),前后要有obj.acquire()和obj.release() """
# 线程 条件 from threading import Condition from threading import Thread def test(con): con.acquire() con.wait() print('Hello, World!') con.release() con = Condition() for i in range(10): Thread(target=test, args=(con, )).start() con.acquire() con.notify(2) con.release() # 注意运行完会发生阻塞