Repository navigation
The message pump's queue is asyncio's queue - #254
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
+26 / −80 across 2 files.
Queueinmessage_pump.pygoes from a 50-line hand copy ofasyncio.Queueto a 15-line subclass of it.Before / after
class Queue(Generic[T])with its own deque,ready_event, wakeup-recheck loop and atask_donethat did nothing.class Queue(asyncio.Queue[T])keeps only what asyncio lacks:peek_nowait()readsself._queue[0]without taking the head from a waiting consumer.activity(from The pilot waits only on pumps that owe work; the queue is the pump's and says so #252): OWING is set in asyncio's_puthook, the same subclass protocolPriorityQueueandLifoQueueuse. SETTLED is set whengetfinds the queue empty.Deleted
task_donestub.asyncio.Queueowns those guarantees.peek_nowaitand 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
getcall. The only synchronous drain isget_nowaitin_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