Skip to content

Instantly share code, notes, and snippets.

@cgarciae
Created July 6, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cgarciae/63aaa78dabc33443c8a61ab74b1c748f to your computer and use it in GitHub Desktop.
Save cgarciae/63aaa78dabc33443c8a61ab74b1c748f to your computer and use it in GitHub Desktop.
from aiohttp import ClientSession, TCPConnector
import asyncio
import sys
import pypeln as pl
limit = 1000
urls = ("http://localhost:8080/{}".format(i) for i in range(int(sys.argv[1])))
async def main():
async with ClientSession(connector=TCPConnector(limit=0)) as session:
async def fetch(url):
async with session.get(url) as response:
return await response.read()
await pl.task.each(
fetch, urls, workers=limit,
)
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment