Last active
May 17, 2016 11:43
-
-
Save shicky/5b8f5d382600c5b46007cab66666a06a 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 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