标签:tip rom join one process rod __name__ rgs art
from multiprocessing import Process,Queue import time def producer(q): for i in range(6): res = ‘包子%s‘ %i time.sleep(0.5) print(‘生产者生产了%s‘%res) q.put(res) def cosumer(q): while True: res = q.get() if res is None:break time.sleep(2) print(‘消费者吃了%s‘%res) if __name__ == ‘__main__‘: q = Queue() #生产者们 p = Process(target=producer,args=(q,)) #消费者们 c1 = Process(target=cosumer,args=(q,)) p.start() c1.start() p.join() q.put(None) #如果是多个消费者,就用多个q.put(None) print(‘主进程‘)
标签:tip rom join one process rod __name__ rgs art
原文地址:https://www.cnblogs.com/yelublue/p/9121498.html