liveBook · Manning

Queue module

As explained in Python Concurrency with asyncio

The queue module is Python's standard-library module for thread-safe queues that coordinate communication between threads.

The queue module provides a thread-safe queue for passing data between threads. A worker can place progress updates into the queue while the main thread retrieves them and updates the user interface, avoiding shared-data race conditions. section 7.4.2

A practical worker-to-UI pattern uses the queue as a handoff point:

  • Have the worker put progress updates into the queue. section 7.4.2
  • Poll the queue from the main UI thread and apply available updates. section 7.4.2

Progress updates in a Tkinter load tester

A Tkinter application stores a Queue, polls it every 25 milliseconds with after, and updates its progress bar from the main thread while an asyncio event loop runs in another thread.

How Python Concurrency with asyncio covers it

How deep it goes
Defines the handoff pattern and polling interval but does not detail queue internals or synchronization primitives.
Examples
Uses a Tkinter load tester that polls progress updates every 25 milliseconds.
What it assumes
Assumes basic threads and Tkinter, while establishing why shared data can create race conditions.
What you can do after
Apply it via queue.Queue to pass worker updates safely to a main-thread user interface.
How it connects
Connects thread safety, race conditions, Tkinter, asyncio, and event loops.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.