Repository navigation
Conversation
When get_nowait() wakes a waiting putter, the freed slot was open until the putter resumed, so a later put() or put_nowait() could take it. The woken putter then found the queue full again and went to the back of the line, putting items out of order. Count slots promised to woken putters in full(), so the slot stays with the putter that was woken for it. This keeps put_nowait() consistent with full() and stays O(1), unlike the approach in pythongh-112501. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Documentation build overview
|
Contributor
Author
|
@YvesDup here is my try to make |
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.
When the queue is full,
get_nowait()pops a waiting putter and wakes it, but the freed slot stays open until that putter resumes. A laterput()(fast path) orput_nowait()can take it; the woken putter then finds the queue full and is re-appended to the end of_putters, so items are put out of order and a waiter can be starved.This PR reserves the freed slot for the woken putter:
get_nowait()increments_reservedwhen it wakes a putter;full()counts reserved slots (qsize() + _reserved >= maxsize).put_nowait(); if it is cancelled after being woken it passes the reservation to the next putter.shutdown()clears the counter.This is the same idea
asyncio.Semaphoreuses for fairness (taking the value on the waiter's behalf). Compared to the earlier attempt (gh-112501):full() is Falsestill guaranteesput_nowait()succeeds;get_nowait()with one waiting putter, thenput_nowait()) succeeds.Behaviour change:
full()may beTruewhileqsize() < maxsize, for as long as a woken putter has not resumed. Documented infull()/put().Getters are left as is: the issue is about the order items enter the queue, and reserving items would change the meaning of
empty().🤖 Generated with Claude Code