classification
Title: coroutine asyncio.wait() does not preserve order of elements
Type: behavior Stage:
Components: asyncio Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, socketpair, vstinner, yselivanov
Priority: normal Keywords:

Created on 2015-06-28 06:30 by socketpair, last changed 2015-11-29 20:43 by socketpair. This issue is now closed.

Messages (3)
msg245899 - (view) Author: Марк Коренберг (socketpair) * Date: 2015-06-28 06:30
If I pass an list of futures/coroutines as (done, _) = asyncio.wait([...]), order of elements in `done` does NOT match order of elements in `wait`'s argument. This is not documented, and I don't know if that is a bug or not.

Also, documentation say:

Wait for the Futures and coroutine objects given by the SEQUENCE futures to complete.

Really, this should be SET, since order is not preserved. Or, sources should be patched to preserve the order. I think, it is not hard to preserve order [in asyncio code].


P.S.

For example, in Tornado, it is guaranteed (and documented) that order is preserved, so I can write

[res1, res2] = yield [fut1(), fut2()]

and it is guaranteed, that res1 - is a result of fut1()
msg245902 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2015-06-28 07:25
The docs say that it returns two *sets* and Python's set datatype is unordered. So that's all you need to know. I don't think there's anything else needed in the docs.
msg255596 - (view) Author: Марк Коренберг (socketpair) * Date: 2015-11-29 20:43
Yes this is not a bug.

Use asyncio.gather(), it preserves order of elements :)
History
Date User Action Args
2015-11-29 20:43:05socketpairsetmessages: + msg255596
2015-06-28 07:25:15gvanrossumsetstatus: open -> closed
resolution: not a bug
messages: + msg245902
2015-06-28 06:30:54socketpaircreate