Skip to content

Commit

Permalink
add default timeout for requests:
Browse files Browse the repository at this point in the history
this is to avoid issues where `urllib3` would complain that there are no
more free connections left (in multi-threaded context)
  • Loading branch information
schlegelp committed Nov 8, 2024
1 parent 0a41dfb commit 81bc387
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dvid/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
'find_lost_ids', 'update_ids', "get_branch_history"]


# Set a global timeout for all requests
HTTP_TIMEOUT = 60


class TimeoutRequestsSession(requests.Session):
def request(self, *args, **kwargs):
kwargs.setdefault("timeout", HTTP_TIMEOUT)
return super(TimeoutRequestsSession, self).request(*args, **kwargs)


def dvid_session(appname=DEFAULT_APPNAME, user=None):
"""Return a default requests.Session() object.
Expand All @@ -68,7 +78,7 @@ def dvid_session(appname=DEFAULT_APPNAME, user=None):
try:
s = DVID_SESSIONS[(appname, user, thread_id, pid)]
except KeyError:
s = requests.Session()
s = TimeoutRequestsSession()
s.params = {'u': user, 'app': appname}
DVID_SESSIONS[(appname, user, thread_id, pid)] = s

Expand Down

0 comments on commit 81bc387

Please sign in to comment.