Skip to content

Instantly share code, notes, and snippets.

@shicky
Last active May 17, 2016 11:43
Show Gist options
  • Save shicky/5b8f5d382600c5b46007cab66666a06a to your computer and use it in GitHub Desktop.
Save shicky/5b8f5d382600c5b46007cab66666a06a to your computer and use it in GitHub Desktop.
import aiohttp
import asyncio
import time
urls_i = [
"http://google.com",
"https://stackoverflow.com"
]
urls = []
for u in urls_i:
for _ in range(0,1000):
urls.append(u)
print("length: {}".format(len(urls)))
sem = asyncio.Semaphore(1000)
def fetch(u):
with (yield from sem):
resp = yield from (aiohttp.request('GET', u))
resp.close()
ts = time.time()
loop = asyncio.get_event_loop()
f = asyncio.wait([fetch(u) for u in urls])
loop.run_until_complete(f)
print(time.time() - ts)
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment