Skip to content
Myr

use settings.timeout_fallback bool for socket.setdefaulttimeout() fallback

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by JensDiemer · committed by JensDiemer · parent 647cdd3 · Browse files · 2 files+12 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+12 added−5 removed

  • other:+12 added−5 removed

2 files+12 added−5 removed

modified:requests/config.py+1 added
55 unmodified lines
56settings = Settings()57settings.base_headers = {'User-Agent': 'python-requests.org'}58settings.accept_gzip = True59settings.proxies = None60settings.timeout_fallback = True # Use socket.setdefaulttimeout() as fallback?
modified:requests/models.py+11 added-5 removed
36 unmodified lines
37 url=None, headers=dict(), files=None, method=None, data=dict(),38 params=dict(), auth=None, cookiejar=None, timeout=None, redirect=False,39 allow_redirects=False, proxies=None):4041 #socket.setdefaulttimeout(timeout)41 #: Float describ the timeout of the request. (Use socket.setdefaulttimeout() as fallback)42 self.timeout = timeout4344 #: Request URL.45 self.url = url
266 unmodified lines
312 except TypeError, err:313 # timeout argument is new since Python v2.6314 if not "timeout" in str(err):315 raise316 317 if settings.timeout_fallback:316 # set global socket timeout317 old_timeout = socket.getdefaulttimeout()318 socket.setdefaulttimeout(self.timeout)318 # fall-back and use global socket timeout (This is not thread-safe!)319 old_timeout = socket.getdefaulttimeout()320 socket.setdefaulttimeout(self.timeout)321 322 resp = opener(req)323 324 if settings.timeout_fallback:325 # restore gobal timeout320 socket.setdefaulttimeout(old_timeout)326 socket.setdefaulttimeout(old_timeout)327328 if self.cookiejar is not None:329 self.cookiejar.extract_cookies(resp, req)330
250 unmodified lines