首页 > 编程语言 > 详细

Python - queue

时间:2017-10-26 23:45:54      阅读:309      评论:0      收藏:0      [点我收藏+]
import threading,time,queue

q=queue.Queue(maxsize = 10)

def product(name):
count = 1
while True:
q.put(count)
print("%s生产了%s个骨头"%(name,count))
count += 1
time.sleep(0.5)

def consumer(name):
while True:
print("%s 消费了 %s 个骨头"%(name,q.get()))
time.sleep(1)

p=threading.Thread(target=product,args=("xsy",))
c=threading.Thread(target=consumer,args=("a",))
c1=threading.Thread(target=consumer,args=("b",))
p.start()
c.start()
c1.start()

Python - queue

原文:http://www.cnblogs.com/xiesongyou/p/7739909.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!