diff --git a/arango/client.py b/arango/client.py index 8424ddfa..7bdd6f4a 100644 --- a/arango/client.py +++ b/arango/client.py @@ -53,6 +53,12 @@ class ArangoClient: False: Do not verify TLS certificate. str: Path to a custom CA bundle file or directory. :type verify_override: Union[bool, str, None] + :param request_timeout: This is the default request timeout (in seconds) + for http requests issued by the client if the parameter http_client is + not secified. The default value is 60. + None: No timeout. + int: Timeout value in seconds. + :type request_timeout: Any """ def __init__( @@ -64,6 +70,7 @@ def __init__( serializer: Callable[..., str] = lambda x: dumps(x), deserializer: Callable[[str], Any] = lambda x: loads(x), verify_override: Union[bool, str, None] = None, + request_timeout: Any = 60, ) -> None: if isinstance(hosts, str): self._hosts = [host.strip("/") for host in hosts.split(",")] @@ -80,7 +87,13 @@ def __init__( else: self._host_resolver = RoundRobinHostResolver(host_count, resolver_max_tries) + # Initializes the http client self._http = http_client or DefaultHTTPClient() + # Sets the request timeout. + # This call can only happen AFTER initializing the http client. + if http_client is None: + self.request_timeout = request_timeout + self._serializer = serializer self._deserializer = deserializer self._sessions = [self._http.create_session(h) for h in self._hosts] @@ -117,6 +130,20 @@ def version(self) -> str: version: str = get_distribution("python-arango").version return version + @property + def request_timeout(self) -> Any: + """Return the request timeout of the http client. + + :return: Request timeout. + :rtype: Any + """ + return self._http.REQUEST_TIMEOUT # type: ignore + + # Setter for request_timeout + @request_timeout.setter + def request_timeout(self, value: Any) -> None: + self._http.REQUEST_TIMEOUT = value # type: ignore + def db( self, name: str = "_system", diff --git a/tests/test_client.py b/tests/test_client.py index 0a170b90..1a6893b7 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -53,6 +53,9 @@ def test_client_attributes(): assert repr(client) == client_repr assert isinstance(client._host_resolver, RandomHostResolver) + client = ArangoClient(hosts=client_hosts, request_timeout=120) + assert client.request_timeout == client._http.REQUEST_TIMEOUT == 120 + def test_client_good_connection(db, username, password): client = ArangoClient(hosts="http://127.0.0.1:8529")