简体   繁体   English

使用ProxyConnector的aiohtttp连接池

[英]aiohtttp connection pooling with ProxyConnector

I was wondering if anyone knows how to do connection pooling with aiohttp using the ProxyConnector as the connector? 我想知道是否有人知道如何使用ProxyConnector作为连接器来与aiohttp建立连接池?

The docs mention how to do this with the TcpConnector or using the Session class, but I can not seem to figure it out. 该文档提到了如何使用TcpConnector或使用Session类来做到这一点,但我似乎无法弄清楚。

Thanks. 谢谢。

The ClientSession object , which handles connection pooling, takes a connector keyword argument: 处理连接池的ClientSession对象带有一个connector关键字参数:

class aiohttp.client.ClientSession(*, connector=None, loop=None, request_class=None, response_class=None, cookies=None, headers=None, auth=None)

if no connector is given, a TCPConnector will be used by default, but you can just specify a ProxyConnector instance, and that will be used instead. 如果未提供connector则默认情况下将使用TCPConnector ,但是您可以仅指定ProxyConnector实例,而将使用该实例。 You can see this logic in the source: 您可以在源代码中看到以下逻辑:

class ClientSession:

    def __init__(self, *, connector=None, loop=None, request_class=None,
                 response_class=None, cookies=None, headers=None, auth=None):
        if loop is None:
            loop = asyncio.get_event_loop()
        self._loop = loop
        self.cookies = http.cookies.SimpleCookie()
        if connector is None:
            connector = aiohttp.TCPConnector(force_close=True, loop=loop)

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

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