New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncio doc: issue in as_completed() doc #71776
Comments
Remark on as_completed() doc by Hynek. https://docs.python.org/dev/library/asyncio-task.html#asyncio.as_completed Futures are yielded in an unexpected order: as soon as a future completes. |
More explicitly: The doc sells the function short. If you have a bunch of futures and want to know as soon as one of them is ready: this is the function for you. The only hint that this is the actual behavior comes from the *name* of the function; not the documentation. |
I am not even sure what the function is supposed to tell me. The documentation is very unclear and the example code does not help. What is "fs" for instance? And why would it return things that are not from fs? |
However, in general you should use a different pattern. Wrap each future in --Guido (mobile) |
Such an idiom is IMHO not the main usefulness of this function tho. As an (untested) example, something like async def f(n):
await asyncio.sleep(n)
return n
for f in asyncio.as_completed([f(3), f(2), f(1)]):
print(await f) will print: 1 That’s *super* useful if you’re coordinating multiple independent external systems and need to process their results as soon as they arrive (and not once they’re *all* done). Maybe it always worked by accident for me but it’s my understanding, that that is what this function is for (and I haven’t found another way to achieve it). That’s why it would be nice if there’d be authoritative docs on what it’s supposed to do. :) |
Well, in that case the idiom will be even simpler: wrap each one in a |
Current docs read as below with an example to show that earliest future is returned. I guess this can be closed. https://docs.python.org/dev/library/asyncio-task.html#asyncio.as_completed Run awaitable objects in the aws set concurrently. Return an iterator of Future objects. Each Future object returned represents the earliest result from the set of the remaining awaitables. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: