Forked from Integralist/Multiple asynchronous HTTP GET requests with Python's aiohttp and asyncio.py
Created
March 1, 2019 14:47
-
-
Save akopitsa/bc9061d46150616d3c24ca8e8a74553f to your computer and use it in GitHub Desktop.
Multiple asynchronous HTTP GET requests with Python's aiohttp and asyncio
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 time | |
import datetime | |
import asyncio | |
import aiohttp | |
domain = 'http://integralist.co.uk' | |
a = '{}/foo?run={}'.format(domain, time.time()) | |
b = '{}/bar?run={}'.format(domain, time.time()) | |
async def get(url): | |
print('GET: ', url) | |
async with aiohttp.ClientSession() as session: | |
async with session.get(url) as response: | |
t = '{0:%H:%M:%S}'.format(datetime.datetime.now()) | |
print('Done: {}, {} ({})'.format(t, response.url, response.status)) | |
loop = asyncio.get_event_loop() | |
tasks = [ | |
asyncio.ensure_future(get(a)), | |
asyncio.ensure_future(get(b)) | |
] | |
loop.run_until_complete(asyncio.wait(tasks)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment