import threading,time,queue
q=queue.Queue(maxsize=10)
def Producer(name):
count=1
while True:
q.put("骨頭%s"%count)
print("生成了骨頭:",count)
count +=1 #count=count +1
time.sleep(0.5)
def Consumer(name):
#while q.qsize()>0:
while True:
print("[%s]取到[%s]並且吃了他..."%(name,q.get()))
time.sleep(1)
p=threading.Thread(target=Producer,args=("Lei",))
c=threading.Thread(target=Consumer,args=("Han×××",))
c2=threading.Thread(target=Consumer,args=("Bily",))
p.start()
c.start()
c2.start()
生產者消費者模型
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Hello Kitty沐浴露順利通過複檢全線產品合格
hellokitty2011
2019-02-23 13:07:39
osi七層模型 與Linux的一些常用命令和權限管理 繼承上篇
夢與時光眠
2019-02-23 13:51:55
網絡分析能力修行模型
易隱者
2019-02-23 13:20:25
MVC與三層架構
StringLong
2019-02-23 00:41:59
Struts框架之ActionServlet(1)
foxle
2019-02-23 00:31:38
I/O多路轉接之select
朔月雲影
2019-02-23 00:21:41
SylixOS文件記錄鎖使用
張榮榮123
2019-02-23 00:15:35
Select 模型1
li19910110
2019-02-23 00:04:20
TCP/IP7層模型
yutianheji
2019-02-23 00:02:04
網絡功能的“公認模型”
route操作
2019-02-22 23:58:10