Skip to content

Instantly share code, notes, and snippets.

@0xsha 0xsha/async-1.py
Created Nov 4, 2019

Embed
What would you like to do?
# 0xsha.io
# 11/2019
import aiohttp
import asyncio
import time
urls = ["https://0xsha.io","https://twitter.com", "https://google.com", "https://yahoo.com", "https://facebook.com", "https://msn.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com",
"https://bing.com", "https://golang.org", "https://twitter.com", "https://netflix.com"
]
async def fetch(session, url):
async with session.get(url) as response:
return await response.text()
async def main():
async with aiohttp.ClientSession() as session:
start = time.time()
print(f"started at {time.strftime('%X')}")
for url in urls:
await fetch(session, url)
end = time.time()
print(f"started at {time.strftime('%X')}")
print(end-start)
if __name__ == '__main__':
asyncio.run(main())
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.