''' event.wait() #设定阻塞,此时线程会被阻塞,等遇到event.set()时,线程会继续运行 event.set() event.clear() # ''' import time,threading class Boss(threading.Thread): def run(self): print('Boss:','今晚加班到10点') time.sleep(1) event.set() time.sleep(8) print('Boss:','现在下班啦') event.set() class Worker(threading.Thread): def run(self): event.wait() print(self.name,'啊啊啊啊!!!!!!') time.sleep(4) event.clear() event.wait() print(self.name,'欧耶!!!!!!!') event.clear() if __name__ == '__main__': event = threading.Event() l = [] for i in range(5): l.append(Worker()) l.append(Boss()) for i in l: i.start() for i in l: i.join() print('ending--------------')