Skip to content

Instantly share code, notes, and snippets.

@pathcl
Created October 13, 2015 18:52
Show Gist options
  • Select an option

  • Save pathcl/df9bb68cda8e2e87d4a3 to your computer and use it in GitHub Desktop.

Select an option

Save pathcl/df9bb68cda8e2e87d4a3 to your computer and use it in GitHub Desktop.
aiohttp
import asyncio
import aiohttp
@asyncio.coroutine
def get_status(url):
code = '000'
try:
res = yield from asyncio.wait_for(aiohttp.request('GET', url), 4)
code = res.status
res.close()
except Exception as e:
print(e)
print(code)
if __name__ == "__main__":
urls = ['http://someurl/index.html'] * 10000
coros = [asyncio.Task(get_status(url)) for url in urls]
loop = asyncio.get_event_loop()
executor = concurrent.futures.ThreadPoolExecutor(5)
loop.set_default_executor(executor)
executor.shutdown(wait=True)
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment