我知道对于 PreparedRequest,我们在session.send
调用中指定超时,其中session
可以是requests.Session
类的实例,正如我已经在这里看到的那样:http: //docs.python-requests.org/en/latest/user/advanced/
但是我需要在发送之前设置超时。从本质上讲,对于 PreparedRequest 对象。因为我使用该session.send
方法作为映射函数,映射到 PreparedRequest 实例。
def async_req2resp(reqs, session):
responses = []
try:
with futures.ThreadPoolExecutor(max_workers=workers) as executor:
for response in executor.map(session.send, requests):
responses.append(response)
except Exception as e:
print('async_requests2responses exception: ' + str(e))
return responses
现在我需要以某种方式指定超时。我该怎么做?上面的代码封装在一个方法中。我将session
对象作为参数。session
在 session.send 的并行执行发生之前,有没有办法可以为将与对象一起发送的所有请求设置超时?
谢谢你。