import threading,time,queue,random

def scz():
while True:
num=random.randint(1,100000)
q.put(num)#放进队列
print("生产者产生了%d数据" %(num))
time.sleep(5)
q.task_done()#完成任务

def xfz():
while True:
item=q.get()#从队列取出
if item is None:
break
print("消费者消费了%d数据"%item)
time.sleep(3)
q.task_done()


if __name__ == '__main__':

q=queue.Queue()


for i in range(4):
threading.Thread(target=scz).start()

for i in range(3):
threading.Thread(target=xfz).start()
版权声明:本文为wfw001-2018原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/wfw001-2018/p/10051257.html