Skip to content

Commit

Permalink
Use socket.setdefaulttimeout(timeout) only if timeout argument doesn'…
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Aug 15, 2011
1 parent 49e5df1 commit 647cdd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ Patches and Suggestions
- Tamás Gulácsi
- Rubén Abad
- Peter Manser
- Jeremy Selie
- Jeremy Selie
- Jens Diemer
15 changes: 13 additions & 2 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self,
params=dict(), auth=None, cookiejar=None, timeout=None, redirect=False,
allow_redirects=False, proxies=None):

socket.setdefaulttimeout(timeout)
#socket.setdefaulttimeout(timeout)
self.timeout = timeout

#: Request URL.
self.url = url
Expand Down Expand Up @@ -306,7 +307,17 @@ def send(self, anyway=False):

try:
opener = self._get_opener()
resp = opener(req)
try:
resp = opener(req, timeout=self.timeout)
except TypeError, err:
# timeout argument is new since Python v2.6
if not "timeout" in str(err):
raise
# set global socket timeout
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(self.timeout)
resp = opener(req)
socket.setdefaulttimeout(old_timeout)

if self.cookiejar is not None:
self.cookiejar.extract_cookies(resp, req)
Expand Down

0 comments on commit 647cdd3

Please sign in to comment.