This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients asvetlov, esrse, josh.r, yselivanov
Date 2019-11-27.03:57:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574827071.16.0.824701436566.issue38874@roundup.psfhosted.org>
In-reply-to
Content
Yes, five outstanding blocked puts can be bypassed by a put that comes in immediately after a get creates space. But this isn't really a problem; there are no guarantees on what order puts are executed in, only a guarantee that once a put succeeds, it's FIFO ordered with respect to all other puts.

Nothing in the docs even implies the behavior you're expecting, so I'm not seeing how even a documentation fix is warranted here. The docs on put clearly say:

"Put an item into the queue. If the queue is full, wait until a free slot is available before adding the item."

If we forcibly hand off on put even when a slot is available (to allow older puts to finish first), then we violate the expectation that waiting is only performed when the queue is full (if I test myqueue.full() and it returns False, I can reasonably expect that put won't block). This would be especially impossible to fix if people write code like `if not myqueue.full(): myqueue.put_nowait()`. put_nowait isn't even a coroutine, so it *can't* hand off control to the event loop to allow waiting puts to complete, even if it wanted to, and it can't fail to put (e.g. by determining the empty slots will be filled by outstanding puts in some relatively expensive way), because you literally *just* verified the queue wasn't full and had no awaits between the test and the put_nowait, so it *must* succeed.

In short: Yes, it's somewhat unpleasant that a queue slot can become free and someone else can swoop in and steal it before older waiting puts can finish. But any change that "fixed" that would make all code slower (forcing unnecessary coroutine switches), and violate existing documentation guarantees.
History
Date User Action Args
2019-11-27 03:57:51josh.rsetrecipients: + josh.r, asvetlov, yselivanov, esrse
2019-11-27 03:57:51josh.rsetmessageid: <1574827071.16.0.824701436566.issue38874@roundup.psfhosted.org>
2019-11-27 03:57:51josh.rlinkissue38874 messages
2019-11-27 03:57:50josh.rcreate