Skip to content

Instantly share code, notes, and snippets.

@cgarciae
Created September 20, 2018 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgarciae/4d35bb9f79c6e72533f26abbaeb17fb2 to your computer and use it in GitHub Desktop.
Save cgarciae/4d35bb9f79c6e72533f26abbaeb17fb2 to your computer and use it in GitHub Desktop.
from aiohttp import ClientSession
from pypeln import io
import asyncio
import sys
async def fetch(url, session):
async with session.get(url) as response:
return await response.read()
async def main():
r = 10
url = "http://google.com"
# r = int(sys.argv[1])
# url = "http://localhost:8080/{}"
async with ClientSession() as session:
data = range(r)
await io.each(lambda i: fetch(url, session), data, workers=1000, run = False)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
print("Finish")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment