import queue
print("-------------queue.Queue----------------")
q = queue.Queue() q.put("one") q.put("two") q.put("three") print(q.get()) print(q.get()) print(q.get()) try: # 队列中没有数据, 会阻塞。 # 阻塞时间到了还没有数据 抛出 queue.Empty 异常 print(q.get(timeout=3)) except queue.Empty as q_e: print('queue empty')
print("-------------queue.LifoQueue----------------")
lq = queue.LifoQueue() lq.put("one") lq.put("two") lq.put("three") print(lq.get()) print(lq.get()) print(lq.get())
print("-------------queue.PriorityQueue----------------")
pq = queue.PriorityQueue() pq.put((1, "Jet")) pq.put((3, "Jack")) pq.put((2, "Judy")) print(pq.get()) print(pq.get()) print(pq.get())
-------------queue.Queue---------------- one two three queue empty -------------queue.LifoQueue---------------- three two one -------------queue.PriorityQueue---------------- (1, 'Jet') (2, 'Judy') (3, 'Jack')