Skip to content

The message pump's queue is asyncio's queue - #254

Merged
trissim merged 1 commit into
mainfrom
queue-is-asyncio-queue
Nov 6, 2026
Merged

trissim merged 1 commit into
mainfrom
queue-is-asyncio-queue

Conversation

@trissim

@trissim trissim commented Nov 6, 2026

Copy link
Copy Markdown

+26 / −80 across 2 files. Queue in message_pump.py goes from a 50-line hand copy of asyncio.Queue to a 15-line subclass of it.

Before / after

  • Before: class Queue(Generic[T]) with its own deque, ready_event, wakeup-recheck loop and a task_done that did nothing.
  • After: class Queue(asyncio.Queue[T]) keeps only what asyncio lacks:

Deleted

  • The deque, the Event, the recheck loop and the task_done stub.
  • Three tests that pinned the copy's own semantics: one item per waiter, recheck after a drained wakeup, no lost wakeup on a cancelled waiter. CPython's asyncio.Queue owns those guarantees.
  • In their place: one test for peek_nowait and one for owing/settled.

Behaviour difference (traced)

The copy re-marked SETTLED every time a woken waiter found the queue drained again. Now that happens once per get call. The only synchronous drain is get_nowait in _discard_pending_messages (message_pump.py:693), which runs after the pump has stopped. So the pilot can see OWING slightly longer, never SETTLED early.

Proof

tests/test_queue.py, test_message_pump.py, test_message_pump_payload_lifetime.py, test_real_app_pump_lifetime.py, test_pilot.py: 169 passed in 21 s in Toad's test env against this checkout.

🤖 Generated with Claude Code

Queue inherits asyncio.Queue and keeps only what is ours: peek_nowait
(reads the head without taking it from a waiting consumer) and the
pump's owing/settled activity, set through asyncio's _put hook and on a
get that finds the queue empty. The hand-copied deque, ready Event,
wakeup recheck and task_done stub are deleted, with the three tests
that pinned them: asyncio already guarantees one item per waiter,
recheck after a drained wakeup, and no lost wakeup on cancel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 15:12
@trissim
trissim merged commit 4916a49 into main Nov 6, 2026
2 of 22 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants