Last active
July 6, 2020 16:32
-
-
Save cgarciae/2eb8c934b2db0fd382b350aa6f4c9a57 to your computer and use it in GitHub Desktop.
client-pypeln-io.py
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
# client-pypeln-pl.task.py | |
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 fetch(url, session): | |
async with session.get(url) as response: | |
return await response.read() | |
pl.task.each( | |
fetch, | |
urls, | |
workers=limit, | |
on_start=lambda: dict(session=ClientSession(connector=TCPConnector(limit=None))), | |
on_done=lambda session: session.close(), | |
run=True, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment