Python:使用HTTPAdapter进行异步编程和pool_maxsize

Python:使用HTTPAdapter进行异步编程和pool_maxsize,python,asynchronous,python-requests,celery,Python,Asynchronous,Python Requests,Celery,使用HTTPAdapter进行异步编程和调用方法的正确方法是什么?所有这些请求都是向同一个域发出的 我正在芹菜中使用eventlet进行异步编程,并在我的一个站点上测试负载。我有一个我调用的方法,它向url发出请求 def get_会话(url): #获取会话返回源 headers,proxy=header\u proxy() #将所有必要的变量设置为“无”,以便在发生错误时 #我们可以确保我们不会崩溃 响应=无 状态代码=无 out_数据=无 内容=无 try: # we are go

使用HTTPAdapter进行异步编程和调用方法的正确方法是什么?所有这些请求都是向同一个域发出的

我正在芹菜中使用eventlet进行异步编程,并在我的一个站点上测试负载。我有一个我调用的方法,它向url发出请求

def get_会话(url): #获取会话返回源 headers,proxy=header\u proxy() #将所有必要的变量设置为“无”,以便在发生错误时 #我们可以确保我们不会崩溃 响应=无 状态代码=无 out_数据=无 内容=无

try:
    # we are going to use request-html to be able to parse the
    # data upon the initial request

    with HTMLSession() as session:
        # you can swap out the original request session here
        # session = requests.session()
        # passing the parameters to the session
        session.mount('https://', HTTPAdapter(max_retries=0, pool_connections=250, pool_maxsize=500))
        response = session.get(url, headers=headers, proxies=proxies)
        status_code = response.status_code
        try:
            # we are checking to see if we are getting a 403 error on all requests. If so,
            # we update the status code
            code = response.html.xpath('''//*[@id="accessDenied"]/p[1]/b/text()''')
            if code:
                status_code = str(code[0][:-1])
            else:
                pass
        except Exception as error:
            pass
            # print(error)
        # assign the content to content
        content = response.content
except Exception as error:
    print(error)
    pass

如果省略
pool\u connections
pool\u maxsize
参数并运行代码,则会出现一个错误,指示没有足够的打开连接。然而,如果我不需要,我不想不必要地打开大量的连接

基于此。。。我猜这适用于主机,而不是异步任务。因此,我将max number设置为每个主机可以重用的最大连接数。如果我多次访问某个域,该连接将被重用。

基于此。。。我猜这适用于主机,而不是异步任务。因此,我将max number设置为每个主机可以重用的最大连接数。如果我多次访问某个域,该连接将被重用。

这与芹菜有什么关系?在芹菜中使用eventlet实现异步
Celery worker-l info-n apple--concurrency=100--pool=eventlet
更新以说明我是如何使用芹菜的,谢谢!这与芹菜有什么关系?通过eventlet在芹菜中实现异步
Celery worker-l info-n apple--concurrency=100--pool=eventlet
更新以说明我是如何使用芹菜的,谢谢!