Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .ci/minimum_requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is postponed because it would set the minimum required verson of ansys-dpf-core to 0.13.7.

pyvista == 0.36.1
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 4 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down
Loading