Sep-20-2020, 08:18 PM
Just a few small changes. I would personally leave the collection of all the results in the
get_results
function:def get_results(urls): async def gather_coro(): return await asyncio.gather(*(get_url_result(url) for url in urls)) url_results = asyncio.run(gather_coro()) return dict(url_results)And then acquiring the single result to
get_url_result
coroutine:async def get_url_result(url): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: return resp.url, await resp.text()