Skip to content

Instantly share code, notes, and snippets.

@privatwolke
privatwolke / gather_dict.py
Created September 20, 2017 13:27
Python: Gather a dictionary of asyncio Task instances while preserving keys
async def gather_dict(tasks: dict):
async def mark(key, coro):
return key, await coro
return {
key: result
for key, result in await gather(
*(mark(key, coro) for key, coro in tasks.items())
)
}