diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 5d3e3cb..17f7724 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -434,6 +434,15 @@ class Client(object): if files is None: files = [] + if longpolling: + # When long-polling, set timeout to 90 sec as a balance + # between a low traffic rate and a still reasonable latency + # time in case of a connection failure. + request_timeout = 90 + else: + # Otherwise, 15s should be plenty of time. + request_timeout = 15 + request = {} req_files = [] @@ -491,10 +500,11 @@ class Client(object): if files: kwargs['files'] = req_files + # Actually make the request! res = self.session.request( method, urllib.parse.urljoin(self.base_url, url), - timeout=90, + timeout=request_timeout, **kwargs) # On 50x errors, try again after a short sleep @@ -547,7 +557,8 @@ class Client(object): # type: (str, str, Dict[str, Any], bool, List[IO]) -> Dict[str, Any] if request is None: request = dict() - return self.do_api_query(request, API_VERSTRING + url, method=method, files=files) + return self.do_api_query(request, API_VERSTRING + url, method=method, + longpolling=longpolling, files=files) def call_on_each_event(self, callback, event_types=None, narrow=None): # type: (Callable, Optional[List[str]], Any) -> None