Skip to content

what about aiohttp.ClientSession? #71

Answered by mjpieters
wedobetter asked this question in Q&A
Discussion options

You must be logged in to vote

You are gating access to the asyncio.gather() call. You haven't made it explicit, but I'm going to assume that that's not what you wanted, but that you instead wanted to limit get() calls.

Gather schedules each entry as a separate task, so they run in parallel independently. You are only rate limiting access to the asyncio.gather() call, and each time execution has reached that line, 100 tasks are created. Those tasks are themselves not rate limited. If you want to rate limit the get() calls, put your with block there, inside the task function.

You can share the limiter between tasks; you could pass it in as an argument:

async def fetch(limiter, something):
    async with limiter:
        a…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@wedobetter
Comment options

@mjpieters
Comment options

@mjpieters
Comment options

@wedobetter
Comment options

@mjpieters
Comment options

Answer selected by mjpieters
Comment options

You must be logged in to vote
1 reply
@mjpieters
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #69 on March 04, 2022 17:54.