# 队列
# 队列 先进先出
# IPC
# from multiprocessing import Queue
# q = Queue(5)
# q.put(1)
# q.put(2)
# q.put(3)
# q.put(4)
# q.put(5)
# print(q.full()) # 队列是否满了,已满话再次放入会阻塞
# print(q.get())
# print(q.get())
# print(q.get())
# print(q.get())
# print(q.get())
# print(q.empty()) # 队列是否空了,空了再去会阻塞
# while True: #不阻塞处理
# try:
# q.get_nowait()
# except:
# print('队列已空')
# time.sleep(0.5)
# for i in range(6):
# q.put(i)
from multiprocessing import Queue,Process
def produce(q):
q.put('hello')
def consume(q):
print(q.get())
if __name__ == '__main__': #在win下才需要这段代码
q = Queue()
p = Process(target=produce,args=(q,))
p.start()
c = Process(target=consume, args=(q,))
c.start()
# 生产者消费者模型
# 队列
# 生产者消费者模型
# 生产者 进程
# 消费者 进程
import time
import random
from multiprocessing import Process,Queue
def consumer(q,name):
while True:
food = q.get()
if food is None: #用q.empty()) 不可靠,也许在上报空后,另外又有生产者放入东西
print('%s获取到了一个空'%name)
break
print('