Skip to content

Commit 7488043

Browse files
committed
feat: detect container image and revise timeout values
1 parent 227ae46 commit 7488043

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/ansys/dpf/core/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def start_local_server(
164164
load_operators=True,
165165
use_docker_by_default=True,
166166
docker_config=RUNNING_DOCKER,
167-
timeout=100.0,
167+
timeout=20.0,
168168
config=None,
169169
use_pypim_by_default=True,
170170
context=None,
@@ -310,7 +310,7 @@ def connect_to_server(
310310
ip=LOCALHOST,
311311
port=DPF_DEFAULT_PORT,
312312
as_global=True,
313-
timeout=100.0,
313+
timeout=10.0,
314314
config=None,
315315
context=None,
316316
):

src/ansys/dpf/core/server_factory.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import os
3333
import subprocess
3434
import time
35+
import json
3536

3637
from ansys.dpf.gate.load_api import (
3738
_find_outdated_ansys_version,
@@ -90,9 +91,19 @@ def __init__(
9091
):
9192
from ansys.dpf.core import LOCAL_DOWNLOADED_EXAMPLES_PATH
9293

93-
if mounted_volumes is None:
94-
# mounted_volumes = {LOCAL_DOWNLOADED_EXAMPLES_PATH: "/tmp/downloaded_examples"}
95-
mounted_volumes = {LOCAL_DOWNLOADED_EXAMPLES_PATH: "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\downloaded_examples"}
94+
if use_docker:
95+
args = ['docker', 'inspect', '-f', 'json', docker_name]
96+
inspect_docker_image = subprocess.run(args, capture_output=True)
97+
if inspect_docker_image.stderr:
98+
raise Exception(f"Specified docker image not found. Verify that the image name '{docker_name}' is valid and the image file is available locally.")
99+
100+
output = json.loads(inspect_docker_image.stdout)
101+
image_os = output[0]['Os']
102+
if mounted_volumes is None:
103+
if image_os == 'linux':
104+
mounted_volumes = {LOCAL_DOWNLOADED_EXAMPLES_PATH: "/tmp/downloaded_examples"}
105+
else: # image is windows
106+
mounted_volumes = {LOCAL_DOWNLOADED_EXAMPLES_PATH: "C:\\Users\\ContainerAdministrator\\AppData\\Local\\Temp\\downloaded_examples"}
96107

97108
self._use_docker = use_docker
98109
self._docker_name = docker_name

src/ansys/dpf/core/server_types.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def read_stdout():
222222

223223

224224
def launch_dpf(
225-
ansys_path, ip=LOCALHOST, port=DPF_DEFAULT_PORT, timeout=100, context: ServerContext = None
225+
ansys_path, ip=LOCALHOST, port=DPF_DEFAULT_PORT, timeout=10, context: ServerContext = None
226226
):
227227
"""Launch Ansys DPF.
228228
@@ -258,7 +258,7 @@ def launch_dpf_on_docker(
258258
ansys_path=None,
259259
ip=LOCALHOST,
260260
port=DPF_DEFAULT_PORT,
261-
timeout=100.0,
261+
timeout=50.0,
262262
):
263263
"""Launch Ansys DPF.
264264
@@ -277,7 +277,7 @@ def launch_dpf_on_docker(
277277
``"DPF_DEFAULT_PORT"``, which is 50054.
278278
timeout : float, optional
279279
Maximum number of seconds for the initialization attempt.
280-
The default is ``10``. Once the specified number of seconds
280+
The default is ``50``. Once the specified number of seconds
281281
passes, the connection fails.
282282
283283
"""
@@ -791,7 +791,7 @@ def __init__(
791791
ansys_path: Union[str, None] = None,
792792
ip: str = LOCALHOST,
793793
port: str = DPF_DEFAULT_PORT,
794-
timeout: float = 100.0,
794+
timeout: float = 10.0,
795795
as_global: bool = True,
796796
load_operators: bool = True,
797797
launch_server: bool = True,
@@ -836,7 +836,6 @@ def __init__(
836836
ansys_path=ansys_path,
837837
ip=ip,
838838
port=port,
839-
timeout=timeout,
840839
)
841840
else:
842841
launch_dpf(ansys_path, ip, port, timeout=timeout, context=context)
@@ -1271,7 +1270,6 @@ def __init__(
12711270
ansys_path=ansys_path,
12721271
ip=ip,
12731272
port=port,
1274-
timeout=timeout,
12751273
)
12761274
else:
12771275
launch_dpf(ansys_path, ip, port, timeout=timeout, context=context)

0 commit comments

Comments
 (0)