标签:任务 time target 生产者消费者 span count 生产者 hid producer
队列:
先进先出
后进先出
VIP(优先级)
import queue # q = queue.LifoQueue()#后进先出 # # q.put(1) # q.put(2) # q.put(3) # print(q.get()) # print(q.get()) # print(q.get()) q = queue.PriorityQueue() q.put((10,"alex")) q.put((-1,"chengrh")) q.put((6,"wangsan")) q.put((4,"zhangsan")) print(q.get()) print(q.get()) print(q.get()) print(q.get())
import threading,time import queue q = queue.Queue(maxsize = 10) def producer(n): count = 1 while True: q.put("骨头 %s" % count ) print("生产了骨头",count) count += 1 time.sleep(0.5) def consumer(n): while True: print("[%s] 取到[%s]并且吃了它..." %(n , q.get())) time.sleep(1) q.task_done() #告知这个任务执行完了 q = queue.Queue() p = threading.Thread(target=producer,args = ("Alex",)) c = threading.Thread(target = consumer,args = ("Chengrh",)) p.start() c.start()
标签:任务 time target 生产者消费者 span count 生产者 hid producer
原文地址:https://www.cnblogs.com/xiaobai005/p/8745753.html