import queue, threading, time

q = queue.Queue(maxsize=10)
def producter(n):
count = 1
while True:
q.put(count)
print('%s 生产了%s 骨头'%(n,count))
time.sleep(1)
count += 1

def consumer(n):
while True:
print('%s 获得了 %s 骨头'%(n,q.get()))
time.sleep(1)


p = threading.Thread(target=producter, args=('alex',))
c = threading.Thread(target=consumer, args=('陈荣华',))
c1 = threading.Thread(target=consumer, args=('王森', ))
p.start()
c.start()
c1.start()


posted on 2018-06-04 19:14  python我的最爱  阅读(200)  评论(0编辑  收藏  举报