1,生产者消费者模型.py
1 import random 2 import time 3 from multiprocessing import Queue, Process 4 5 def producer(name,food,q): 6 for i in range(4): 7 time.sleep(random.randint(1,3)) 8 f = '%s生产了%s%s'%(name,food,i) 9 print(f) 10 q.put(f) 11 12 def consumer(q,name): 13 while True: 14 food = q.get() 15 if food is None: 16 print('%s获取到了一个空',name) 17 break 18 print('