04 信号量
import time import random from multiprocessing import Process,Semaphore def f1(i,s): s.acquire() print('%s男嘉宾到了'%i) time.sleep(random.randint(1,3)) s.release() if __name__ == '__main__': s = Semaphore(4) #计数器4,acquire一次减一,为0 ,其他人等待,release加1, for i in range(10): p = Process(target=f1,args=(i,s)) p.start()