diff --git a/src/ansys/dpf/core/server.py b/src/ansys/dpf/core/server.py index 00d0e48a64b..fd8b9e75ebf 100644 --- a/src/ansys/dpf/core/server.py +++ b/src/ansys/dpf/core/server.py @@ -302,7 +302,7 @@ def connect_to_server( ip=LOCALHOST, port=DPF_DEFAULT_PORT, as_global=True, - timeout=5, + timeout=10.0, config=None, context=None, ): @@ -367,6 +367,7 @@ def connect(): as_global=as_global, launch_server=False, context=context, + timeout=timeout, ) else: server = server_type(as_global=as_global, context=context) diff --git a/src/ansys/dpf/core/server_types.py b/src/ansys/dpf/core/server_types.py index b5e1d638d9a..db360af1cf6 100644 --- a/src/ansys/dpf/core/server_types.py +++ b/src/ansys/dpf/core/server_types.py @@ -766,7 +766,6 @@ def __init__( launch_server: bool = True, docker_config: DockerConfig = RUNNING_DOCKER, use_pypim: bool = True, - num_connection_tryouts: int = 3, context: server_context.AvailableServerContexts = server_context.SERVER_CONTEXT, ): # Load DPFClientAPI @@ -786,6 +785,7 @@ def __init__( address = f"{ip}:{port}" self._remote_instance = None + start_time = time.time() if launch_server: if ( is_pypim_configured() @@ -818,7 +818,7 @@ def __init__( self._input_port = port self.live = True self._create_shutdown_funcs() - self._check_first_call(num_connection_tryouts) + self._check_first_call(timeout=timeout - (time.time() - start_time)) # Pass remaining time if context: if context == core.AvailableServerContexts.no_context: self._base_service.initialize() @@ -831,15 +831,16 @@ def __init__( pass self.set_as_global(as_global=as_global) - def _check_first_call(self, num_connection_tryouts): - for i in range(num_connection_tryouts): + def _check_first_call(self, timeout: float): + start_time = time.time() + while time.time() - start_time < timeout: try: - self.version + _ = self.version break except errors.DPFServerException as e: - if ("GOAWAY" not in str(e.args) and "unavailable" not in str(e.args)) or i == ( - num_connection_tryouts - 1 - ): + if "GOAWAY" in str(e.args) or "unavailable" in str(e.args): + time.sleep(0.5) + else: raise e @property