与进程的事件相似
# 事件,模拟连接数据库 import time from threading import Event, Thread def wait(e): while 1: e.wait(1) if e.is_set(): print('等待成功') break else: print('失败') def check(e): time.sleep(2) e.set() e = Event() Thread(target=check, args=(e, )).start() Thread(target=wait, args=(e, )).start()