From 398f703f2ef4daa83f9db8f5d199b1a719f6f01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Thu, 15 May 2025 07:56:33 +0200 Subject: [PATCH 1/3] remove hack to consider timeout on start dpf server because this is now done in dpf core. --- .../_connect_to_or_start_server.py | 31 ------------------- tests/conftest.py | 21 +++---------- 2 files changed, 4 insertions(+), 48 deletions(-) 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..d8bf830974 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 @@ -26,41 +26,11 @@ 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.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 +83,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 From 2610db1c3fd834c32f59ca480ce4b556b6581813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Thu, 15 May 2025 08:20:01 +0200 Subject: [PATCH 2/3] fix formatting and imports --- .../composites/server_helpers/_connect_to_or_start_server.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 d8bf830974..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,12 +21,10 @@ # 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 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 From d2375f473e16ab8ae6f925b648305fa4f6b743b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Roos?= Date: Thu, 15 May 2025 08:55:00 +0200 Subject: [PATCH 3/3] update minimum_requirements.txt --- .ci/minimum_requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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