queue

  • implements multi-producer, multi-consumer queues
  • implements all the required locking semantics
In [ ]:
def show_queue(q):
    

queue.Queue

  • Basic FIFO Queue
In [ ]:
from queue import Queue

q = Queue()

for i in range(4):
    q.put(i)
    
print(q.qsize()) # 4
print(q.empty()) # False
print(q.full()) # False

while not q.empty():
    print(q.get(), end = ' ') # 0 1 2 3

queue.LifoQueue

  • a LIFO queue
In [ ]:
from queue import LifoQueue

q = LifoQueue()

for i in range(4):
    q.put(i)
    
while not q.empty():
    print(q.get(), end = ' ') # 3 2 1 0

queue.PriorityQueue

In [ ]:
from queue import PriorityQueue

q = PriorityQueue()

q.put(1)
q.put(4)
q.put(2)
q.put(5)

while not q.empty():
    print(q.get(), end = ' ') # 1 2 4 5