pu369com

Python queue (队列)

 

import threading
import time
import queue


def producer():
    count = 1
    while 1:
        q.put('No.%i' % count)
        print('Producer put No.%i' % count)
        time.sleep(1)
        count += 1


def customer(name):
    while 1:
        print('%s get %s' % (name, q.get()))
        time.sleep(1.5)


q = queue.Queue(maxsize=5)
p = threading.Thread(target=producer, )
c = threading.Thread(target=customer, args=('jack', ))
p.start()
c.start()

  

 

参考:节选自 https://www.cnblogs.com/dbf-/p/11118628.html

posted on 2023-04-11 19:48  pu369com  阅读(23)  评论(0编辑  收藏  举报

导航