← All notes

Python asyncio queues: FIFO, priority, and LIFO queues for tasks

Answer: asyncio queues follow the queue module's shapes, but they are for async/await code and are not thread-safe.

FIFO queues and size

The classes are designed to be similar to those in the queue module.

They are not thread-safe, and they are meant for async/await code.

Methods of asyncio queues don't have a timeout parameter; use the asyncio.wait_for() function to do queue operations with a timeout.

Queue is a first in, first out queue.

If maxsize is less than or equal to zero, the queue is considered infinite.

qsize() returns the current number of items, which is always known.

Get, put, join, and shutdown

get removes and returns an item, waiting if the queue is empty.

It raises QueueShutDown if the queue was shut down and is empty, or if it was shut down immediately.

get_nowait returns an item if one is already there, otherwise it raises QueueEmpty.

put adds an item, waiting for a free slot if the queue is full, and it raises QueueShutDown after a shutdown.

put_nowait adds an item without blocking, or raises QueueFull when no slot is free.

The unfinished-task count rises when an item is added and falls when a consumer calls task_done to say work on that item is finished.

join blocks until every item has been received and processed, which is when that count drops to zero.

shutdown puts the queue into shutdown mode so it can no longer grow, and later put calls raise QueueShutDown.

PriorityQueue returns entries in priority order, lowest first, usually as (priority_number, data) tuples.

LifoQueue is a variant of Queue that retrieves most recently added entries first.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Queues; CPython, Queues documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, Queues; CPython, Queues documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:mzm5df0b

iinventedlight. 2026. "Python asyncio queues: FIFO, priority, and LIFO queues for tasks." iinventedlight Library, iil:note:mzm5df0b, version of 2026-11-26. https://iinventedlight.com/library/notes/python-asyncio-queue/. License: CC-BY-4.0.

@misc{iil_note_mzm5df0b,
  author = {{iinventedlight}},
  title = {{Python asyncio queues: FIFO, priority, and LIFO queues for tasks}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/python-asyncio-queue/},
  note = {Permanent ID iil:note:mzm5df0b. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-asyncio-queue.md.