标签:from def pre dom print time color tar rom
import time import random from multiprocessing import Process,Event def cars(e,i): if not e.is_set(): print(‘car%d在等待‘%i) e.wait() print(‘\033[33mcar%i通过\033[0m‘ % i) def light(e): while True: if e.is_set(): e.clear() print(‘\033[31m红灯亮了\033[0m‘) else: e.set() print(‘\033[32m绿灯亮了\033[0m‘) time.sleep(2) if __name__ ==‘__main__‘: e = Event() p = Process(target=light,args=(e,)) p.start() for i in range(1,21): p = Process(target=cars,args=(e,i)) p.start() time.sleep(random.random())
标签:from def pre dom print time color tar rom
原文地址:https://www.cnblogs.com/kuraki/p/9606967.html