如果新的请求会话在不同的方法中实例化,那么......
myutil.py
import requests
def method1():
s1 = requests.Session()
def method2():
s1 = requests.Session()
requests.packages.urllib3.poolmanager.PoolManager
绑定在哪里?它是全局绑定的,以便连接池在s1和s2之间共享,还是绑定到每个方法的堆栈,以便s1和s2具有不同的连接池?
如果它绑定到每个方法的堆栈,我有什么选项来共享连接池?例如,我应该创建一个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)