anyio: A way to collect results upon exiting task group
In asyncio, there’s await asyncio.gather(..a..lot..of..tasks).
Is it possible to somehow emulate this with anyio?
I’m thinking of something like this maybe:
async with create_task_group() as tg:
await tg.spawn(t1)
await tg.spawn(t2)
print(tg.results) # t1_res, t2_res
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 26 (14 by maintainers)
It’s well within your rights to wontfix this, but I will chip in my $0.02 and say when I found out anyio/trio don’t have good
gatherergonomics my interest waned pretty significantly. In other words, I findgatherin asyncio very, very good. Which is a little unfortunate because anyio/trio cancellation scopes are so awesome.This discussion already links to a reasonably simple implementation of
gatheron top of anyio.Meanwhile, I’ve implemented an
asyncio.gather()interface as follows: https://github.com/sanitizers/octomachinery/commit/839d4bfab74e5ebf5712a08383d77ef5185db301.(Posting it here in case somebody else googles this issue)
As with trio, and threads, you’re supposed to use either a queue/memory channel,
deque,dictor something else to store the results of the tasks. I have no plans of implementing any other means of task result retrieval.