import threading,time import queue q = queue.Queue(maxsize=10) def Producer(name):#生产者 count=1 while True: q.put("骨头%s"%count) print("生产了骨头",count) count +=1 time.sleep(2) def Consumer(name):#消费者 while True: time.sleep(1) print("[%s] 取到[%s] 并且吃了它。。。"%(name,q.get())) p =threading.Thread(target=Producer,args=("Alex",)) c =threading.Thread(target=Consumer,args=("goupang",)) c1 =threading.Thread(target=Consumer,args=("baipang",)) p.start() c.start() c1.start()
python-queue队列-生产者消费者
猜你喜欢
转载自www.cnblogs.com/fuyuteng/p/9210120.html
今日推荐
周排行