Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default concurrency level with asyncio in Python?

I'm using Python Asyncio to do a lot of HTTP requests.

I'm wondering what is the default concurrency level of Asyncio or how many HTTP requests would be happening in parallel at any given time?

The code I'm using to do the HTTP requests you can find below:

async def call_url(self, session, url):
    response = await session.request(method='GET', url=url)
    return response


async def main(self, url_list):
    async with aiohttp.ClientSession() as session:
        res = await asyncio.gather(*[self.call_url(session, url) for url in url_list])
        return res
like image 702
fshabashev Avatar asked Apr 09 '26 12:04

fshabashev


1 Answers

There is no built-in limit in asyncio, but there is one in aiohttp. The TCPConnector limits the number of connections to 100 by default. You can override it by creating a TCPConnector with a different limit and passing it to the session.

like image 105
user4815162342 Avatar answered Apr 12 '26 09:04

user4815162342



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!