简体   繁体   English

Python 中的 asyncio 的默认并发级别是多少?

[英]What is the default concurrency level with asyncio in Python?

I'm using Python Asyncio to do a lot of HTTP requests.我正在使用 Python Asyncio 来做很多 HTTP 请求。

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?我想知道 Asyncio 的默认并发级别是多少,或者在任何给定时间并行发生多少 HTTP 请求?

The code I'm using to do the HTTP requests you can find below:我用来执行 HTTP 请求的代码您可以在下面找到:

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

There is no built-in limit in asyncio, but there is one in aiohttp. asyncio 中没有内置限制,但 aiohttp 中有一个。 The TCPConnector limits the number of connections to 100 by default.默认情况下, TCPConnector将连接数限制为 100。 You can override it by creating a TCPConnector with a different limit and passing it to the session.您可以通过创建具有不同限制的TCPConnector并将其传递给 session 来覆盖它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM