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 esrse
Recipients asvetlov, esrse, yselivanov
Date 2019-11-21.03:25:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574306754.82.0.07273997342.issue38874@roundup.psfhosted.org>
In-reply-to
Content
Hi

The python document says that asyncio.Queue is FIFO queue. But it is not true
when the queue is full and multi tasks are putting items into it
simultaneously. I know the document does not explicitly mention that
asyncio.Queue is multi producer queue, but also there does not exist any note
that it may be corrupt if used by multi producers.

I found the below scenario happens when the asyncio.Queue is full and multi
tasks are putting into it simultaneously. Let me explain this.

When a queue is full, putters are awaiting here: https://github.com/python/cpython/blob/d67279147ace3b63187e5d75a15c345264f39e85/Lib/asyncio/queues.py#L125

And the first of them is waken up here: https://github.com/python/cpython/blob/d67279147ace3b63187e5d75a15c345264f39e85/Lib/asyncio/queues.py#L188

Before the first putter hands over the control of execution, new putter
calls the .put() method so the queue is not full at this point that it calls
.put_nowait() immediately here: https://github.com/python/cpython/blob/d67279147ace3b63187e5d75a15c345264f39e85/Lib/asyncio/queues.py#L140

If this happens the new putter puts earlier than other awaiting putters.

I hope the queue gets fixed to work correctly in this case.

Thanks,

  Junyeong
History
Date User Action Args
2019-11-21 03:25:54esrsesetrecipients: + esrse, asvetlov, yselivanov
2019-11-21 03:25:54esrsesetmessageid: <1574306754.82.0.07273997342.issue38874@roundup.psfhosted.org>
2019-11-21 03:25:54esrselinkissue38874 messages
2019-11-21 03:25:54esrsecreate