如果一个新的请求会话以不同的方法实例化,像这样......
myutil.py
import requests
def method1():
s1 = requests.Session()
def method2():
s1 = requests.Session()
requests.packages.urllib3.poolmanager.PoolManager
界限在哪里?是全局绑定的,让s1和s2共享连接池,还是绑定到每个方法的栈,让s1和s2有不同的连接池?
如果它绑定到每个方法的堆栈,我有哪些选项来共享连接池?例如,我是否应该创建一个传输适配器,然后在方法之间共享:
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)