Python queue Module
Example
Create a FIFO queue, put an item, then get it back:
import queue
q = queue.Queue()
q.put('task1')
print(q.get())
Try it Yourself »
Definition and Usage
The queue module provides synchronized queue classes for multi-producer, multi-consumer scenarios.
Use it to safely pass work between threads using FIFO, LIFO, or priority ordering.
Members
Member | Description |
---|---|
Empty | Exception raised when a non-blocking get finds the queue empty. |
Full | Exception raised when a non-blocking put finds the queue full. |
LifoQueue | Thread-safe LIFO queue (stack). |
PriorityQueue | Thread-safe priority queue (lowest first). |
Queue | Thread-safe FIFO queue. |
ShutDown | Exception raised when put() or get() is called on a shut down queue (3.13+). |
SimpleQueue | Unbounded FIFO queue with minimal locking. |
empty() | Return True if the queue is empty, False otherwise. |
full() | Return True if the queue is full, False otherwise. |
get() | Remove and return an item from the queue. |
get_nowait() | Remove and return an item without blocking (raises Empty if empty). |
join() | Block until all tasks have been processed. |
put() | Put an item into the queue. |
put_nowait() | Put an item into the queue without blocking (raises Full if full). |
qsize() | Return the approximate size of the queue. |
shutdown() | Shut down the queue, preventing further put() operations (3.13+). |
task_done() | Indicate that a formerly enqueued task is complete. |