Improving asyncio.gather

Can we do something about asyncio.gather so that it can accept a list or set of coroutines, not just manually writing in the coroutines? That would be totally awesome

You can use the *args notation. E.g.

a = []
for i in range(10):
    a.append(Task(...))
results = await gather(*a)

Oh, so unpacking before actually passing the tasks into gather works. Wonder why I hadn’t thought of that in the first place. Thanks, Sir

1 Like

For what it’s worth, I’ve always found it strange that asyncio.gather() takes awaitables as indivisual positional arguments, but asyncio.wait() only accepts an iterable of awaitables as the first argument.

4 Likes