Created
November 16, 2017 11:12
-
-
Save tritium21/302af640dc6436b6d8c1137096c8e062 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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