diff --git a/.ci/minimum_requirements.txt b/.ci/minimum_requirements.txt index b09c5a7325..98ac75e3c9 100644 --- a/.ci/minimum_requirements.txt +++ b/.ci/minimum_requirements.txt @@ -1,6 +1,7 @@ # Contains minimum requirements that we support numpy == 1.25.0 matplotlib == 3.8.0 -# result info for LSDyna is supported since Dec 23 -ansys-dpf-core == 0.10.1 +# result info for LSDyna is supported since Dec 23 (0.10.1) +# handling of timeout on start server is supported since 0.13.7 +ansys-dpf-core == 0.13.7 pyvista == 0.36.1 diff --git a/src/ansys/dpf/composites/server_helpers/_connect_to_or_start_server.py b/src/ansys/dpf/composites/server_helpers/_connect_to_or_start_server.py index 0b448cb91e..d5244124e9 100644 --- a/src/ansys/dpf/composites/server_helpers/_connect_to_or_start_server.py +++ b/src/ansys/dpf/composites/server_helpers/_connect_to_or_start_server.py @@ -21,46 +21,14 @@ # SOFTWARE. """Helpers to connect to or start a DPF server with the DPF Composites plugin.""" -from collections.abc import Callable import os from typing import Any -from ansys.dpf.core import connect_to_server -from ansys.dpf.core import server as _dpf_server -from ansys.dpf.core import start_local_server +from ansys.dpf.core import connect_to_server, start_local_server from ansys.dpf.composites.server_helpers._load_plugin import load_composites_plugin -def _try_until_timeout(fun: Callable[[], Any], error_message: str, timeout: int = 10) -> Any: - """Try to run a function until a timeout is reached. - - Before the timeout is reached, all exceptions are ignored and a retry happens. - """ - import time - - tstart = time.time() - while (time.time() - tstart) < timeout: - time.sleep(0.001) - try: - return fun() - except Exception: # pylint: disable=broad-except - pass - raise TimeoutError(f"Timeout is reached: {error_message}") - - -def _wait_until_server_is_up(server: _dpf_server) -> Any: - # Small hack to check if the server is up. - # The DPF server should check this in the ``connect_to_server`` function, but - # that's currently not the case. - # https://github.com/ansys/pydpf-core/issues/414 - # We use the fact that server.version throws an error if the server - # is not yet connected. - _try_until_timeout( - lambda: server.version, "Failed to connect to the DPF server before timing out." - ) - - def connect_to_or_start_server( port: int | None = None, ip: str | None = None, ansys_path: str | None = None ) -> Any: @@ -113,7 +81,6 @@ def connect_to_or_start_server( f"(Ansys 2023 R2) or later. Your version is currently {server.version}.", ) - _wait_until_server_is_up(server) # Note: server.ansys_path contains the computed Ansys path from # dpf.server.start_local_server. It is None if # a connection is made to an existing server. diff --git a/tests/conftest.py b/tests/conftest.py index ae4ae13e6b..fd91a99662 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,10 +36,6 @@ import ansys.dpf.core as dpf import pytest -from ansys.dpf.composites.server_helpers._connect_to_or_start_server import ( - _try_until_timeout, - _wait_until_server_is_up, -) from ansys.dpf.composites.server_helpers._load_plugin import load_composites_plugin from ansys.dpf.composites.server_helpers._versions import version_equal_or_later @@ -311,21 +307,12 @@ def start_server_process(): ) with start_server_process() as server_process: - # Workaround for dpf bug. The timeout is not respected when connecting - # to a server:https://github.com/ansys/pydpf-core/issues/638 - # We just try until connect_to_server succeeds - def start_server(): - if server_process.port: - return dpf.server.connect_to_server(port=server_process.port) - else: - return server_process.server - - server = _try_until_timeout(start_server, "Failed to start server.") - - _wait_until_server_is_up(server) + if server_process.port: + server = dpf.server.connect_to_server(port=server_process.port) + else: + server = server_process.server load_composites_plugin(server, ansys_path=installer_path) - yield server