消费者 生产者



import queue import threading import time def producer(name): cont = 0 while True: print('%s生产骨头'%name,cont) q.put(cont) cont += 1 time.sleep(0.3) def consumer(name): cont = 0 while True: print('%s吃骨头'%name,q.get()) cont += 1 time.sleep(0.3) q = queue.Queue(maxsize=5) p = threading.Thread(target=producer,args=('Alxe',)) p.start() c = threading.Thread(target=consumer,args=('武sir',)) c.start()

  

posted @ 2017-01-13 16:30  200ML  阅读(124)  评论(0编辑  收藏  举报