Skip to content

Instantly share code, notes, and snippets.

@tritium21
Created November 16, 2017 11:12
Show Gist options
  • Select an option

  • Save tritium21/302af640dc6436b6d8c1137096c8e062 to your computer and use it in GitHub Desktop.

Select an option

Save tritium21/302af640dc6436b6d8c1137096c8e062 to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
URLS = [
"https://google.com",
"https://github.com",
"https://example.org",
]
DONE = {}
async def fetch(session, url):
async with session.get(url) as resp:
return url, len(await resp.text())
async def main():
async with aiohttp.ClientSession() as session:
print(dict(await asyncio.gather(*[asyncio.ensure_future(fetch(session, u)) for u in URLS])))
asyncio.get_event_loop().run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment