python-requests - urllib3连接池绑定(bind)在哪里?

标签 python-requests connection-pooling urllib3

如果一个新的请求 session 在不同的方法中被实例化,就像这样......

myutil.py

import requests

def method1():
    s1 = requests.Session()

def method2():
    s1 = requests.Session()

requests.packages.urllib3.poolmanager.PoolManager 绑定(bind)在哪里?它是全局绑定(bind)以便在 s1 和 s2 之间共享连接池,还是绑定(bind)到每个方法的堆栈以便 s1 和 s2 具有不同的连接池?

如果它绑定(bind)到每个方法的堆栈,我有什么选项可以共享连接池?例如,我应该创建一个 transport adapter 吗?然后在方法之间共享比:

myutil.py

import requests
from requests.adapters import HTTPAdapter

httpAdapter = HTTPAdapter(pool_connections=10, pool_maxsize=100)

def method1():
    s1 = requests.Session()
    s1.mount('https://', httpAdapter)

def method2():
    s1 = requests.Session()
    s2.mount('https://', httpAdapter)

最佳答案

我已经做了一些测试,似乎池没有全局绑定(bind)。

参见 here了解更多信息。

关于python-requests - urllib3连接池绑定(bind)在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29027969/

相关文章:

python - 类型错误 : urlopen() got multiple values for keyword argument 'body' while executing tests through Selenium and Python on Kubuntu 14. 04

python - 从Docker容器300秒后,Python HTTP GET引发异常

python - 请求库无法正确发布,但 urllib 成功 [python]

python - 每个域/url "SSLError certificate verify failed"

python - 使用 Python 请求和响应模拟文件下载

单独的数据库类中的 MySQL 连接池 - 如何?

python - 如何修复 ImportError : No module named packages. urllib3?

delphi - IdHTTP服务器 : Share ADOConnection

java - 使用信号量管理连接池 (Java)

python - 脚本突然停止爬取,无错误无异常