python 生产者消费者模型

 1 import queue
 2 import threading
 3 
 4 q = queue.Queue(10)
 5 def product(i):
 6     print('put:'+ str(i))
 7     q.put(i)
 8 
 9 def customer(i):
10     msg = q.get()
11     print(msg)
12 
13 for i in range(12):
14     t = threading.Thread(target=product,args=(i,))
15     t.start()
16 
17 for i in range(10):
18     t = threading.Thread(target=customer,args=(i,))
19     t.start()

 

posted @ 2017-03-02 21:59  Erick-LONG  阅读(178)  评论(0编辑  收藏  举报