Skip to content

Instantly share code, notes, and snippets.

@Natim
Created September 22, 2014 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natim/bba77fc2173b7b92b278 to your computer and use it in GitHub Desktop.
Save Natim/bba77fc2173b7b92b278 to your computer and use it in GitHub Desktop.
Python3 version of Boom
import asyncio
import aiohttp
def fetch_page(url, idx, num):
# Num per client
for i in range(num):
response = yield from aiohttp.request('GET', url)
if response.status == 200:
print("data fetched successfully for: %d, %d" % (idx, i))
else:
print("data fetch failed for: %d, %d" % (idx, i))
print(response.content, response.status)
def main():
url = 'http://localhost:5000'
num = 10
# Concurrency
urls = [url] * 100
coros = []
for idx, url in enumerate(urls):
coros.append(asyncio.Task(fetch_page(url, idx, num)))
yield from asyncio.gather(*coros)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment