Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import asyncio
import json
import time
import aiohttp
result = []
async def download_site(session, url):
async with session.get(url) as response:
resp_json = await response.json()
print("url", url, resp_json)
result.append(resp_json)
async def download_all_sites(_sites):
async with aiohttp.ClientSession() as session:
tasks = []
for url in _sites:
task = asyncio.ensure_future(download_site(session, url))
tasks.append(task)
await asyncio.gather(*tasks, return_exceptions=True)
if __name__ == "__main__":
sites = [
"https://reqres.in/api/users",
"http://dummy.restapiexample.com/api/v1/employees",
]
start_time = time.time()
asyncio.get_event_loop().run_until_complete(download_all_sites(sites))
# print(result)
print("total time took is %s" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.