Without a timeout, requests will block until a response is received. This ensures a timeout is set for each request made so that if servers are slow to respond, we don't get stuck waiting forever.
Signed-off-by: Jeremy Cline jeremy@jcline.org
:+1:
rebased
Pull-Request has been merged by jcline
Could also just set it globally on the requests.Session... but this works.
The tuple syntax for timeouts is interesting. Why 6.1 and 15 seconds? Looks a bit random :-)
Unfortunately (IIRC) you have to re-create the adapters inside the session and pass it kwargs for the underlying urllib3 connection pool. It's doable, but not as clear. I'd definitely take that approach if we had tons of requests sprinkled around, and maybe in the future it's worth doing it that way.
As for the values, 3 is the default TCP re-transmission time so a value slightly larger than a multiple of 3 allows for a lost packet to be re-transmitted (in this case twice) before giving up on the connect call. 15 seconds is a number I just picked out of the hat as a reasonable number to give up on a read call.
connect
read
I was planning to document all the configuration values anyway, so I'll leave notes about those values when I do that.
Ah that's neat about the 6.1 seconds.
Hmm for some reason I thought you could just set .timeout on the session and it magically applied to all requests, but now I can't find that described in the docs so I'm not sure...
.timeout
Setting timeout on the session sounds like a good idea, but I do not think requests currenly supports it in the code.
http://docs.python-requests.org/en/master/_modules/requests/sessions/
It's a commonly-filed issue on requests, but the timeout is a transport layer concern. One approach to setting a default timeout with the HTTPAdapter can be found here.
Without a timeout, requests will block until a response is received.
This ensures a timeout is set for each request made so that if servers
are slow to respond, we don't get stuck waiting forever.
Signed-off-by: Jeremy Cline jeremy@jcline.org