Created
July 6, 2020 16:32
-
-
Save cgarciae/63aaa78dabc33443c8a61ab74b1c748f 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
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