38
38
import inspect
39
39
import logging
40
40
import os
41
+ import tempfile
42
+ import time
41
43
from typing import Any , Dict
42
44
43
45
from ansys .fluent .core .fluent_connection import FluentConnection , _get_max_c_int_limit
50
52
UIMode ,
51
53
_get_argvals_and_session ,
52
54
)
55
+ from ansys .fluent .core .session import _parse_server_info_file
53
56
from ansys .fluent .core .session_meshing import Meshing
54
57
from ansys .fluent .core .session_pure_meshing import PureMeshing
55
58
from ansys .fluent .core .session_solver import Solver
@@ -193,6 +196,54 @@ def __call__(self):
193
196
)
194
197
195
198
199
+ def get_ip_port_password (
200
+ file_service ,
201
+ filename = "sifile.txt" ,
202
+ max_retries = 20 ,
203
+ wait_time_between_retries = 1 , # seconds
204
+ ):
205
+ """
206
+ Downloads the file with retries and parses server info.
207
+
208
+ Parameters
209
+ ----------
210
+ file_service: PimFileTransferService
211
+ Service object with method download_file(filename, target_dir).
212
+ filename: str
213
+ Name of the file to download.
214
+ max_retries: int
215
+ Maximum number of attempts.
216
+ wait_time_between_retries: float
217
+ Seconds to wait between retries (can be fractional, e.g., 0.5 for half a second).
218
+
219
+ Returns
220
+ -------
221
+ Tuple (ip, port, password) parsed from the downloaded file.
222
+
223
+ Raises
224
+ ------
225
+ TimeoutError
226
+ If unable to download the server info file after multiple retries.
227
+ """
228
+ with tempfile .TemporaryDirectory (prefix = "fluent_sifile_" ) as tmpdir :
229
+ for attempt in range (1 , max_retries + 1 ):
230
+ try :
231
+ file_service .download_file (filename , tmpdir )
232
+ break
233
+ except Exception as ex :
234
+ logger .warning (
235
+ f"Attempt { attempt } of { max_retries } failed to download { filename } : { ex } "
236
+ )
237
+ if attempt == max_retries :
238
+ raise TimeoutError (
239
+ f"Failed to download file '{ filename } ' after { max_retries } attempts "
240
+ f"with { wait_time_between_retries } s between retries."
241
+ ) from ex
242
+ time .sleep (wait_time_between_retries )
243
+
244
+ return _parse_server_info_file (os .path .join (tmpdir , filename ))
245
+
246
+
196
247
def launch_remote_fluent (
197
248
session_cls ,
198
249
start_transcript : bool ,
@@ -232,6 +283,11 @@ def launch_remote_fluent(
232
283
-------
233
284
Meshing | PureMeshing | Solver | SolverIcing
234
285
Session object.
286
+
287
+ Raises
288
+ ------
289
+ TimeoutError
290
+ If unable to download the server info file after multiple retries.
235
291
"""
236
292
237
293
pim = pypim .connect ()
@@ -245,6 +301,10 @@ def launch_remote_fluent(
245
301
246
302
instance .wait_for_ready ()
247
303
304
+ ip , port , password = get_ip_port_password (
305
+ file_service = PimFileTransferService (pim_instance = instance )
306
+ )
307
+
248
308
channel = instance .build_grpc_channel (
249
309
options = [
250
310
("grpc.max_send_message_length" , _get_max_c_int_limit ()),
@@ -253,6 +313,9 @@ def launch_remote_fluent(
253
313
)
254
314
255
315
fluent_connection = create_fluent_connection (
316
+ ip = ip ,
317
+ port = port ,
318
+ password = password ,
256
319
channel = channel ,
257
320
cleanup_on_exit = cleanup_on_exit ,
258
321
instance = instance ,
@@ -288,11 +351,20 @@ def create_fluent_instance(
288
351
289
352
290
353
def create_fluent_connection (
291
- channel , cleanup_on_exit : bool , instance , launcher_args : Dict [str , Any ] | None
354
+ ip : str ,
355
+ port : int ,
356
+ password : str ,
357
+ channel ,
358
+ cleanup_on_exit : bool ,
359
+ instance ,
360
+ launcher_args : Dict [str , Any ] | None ,
292
361
):
293
362
"""Create a Fluent connection."""
294
363
295
364
return FluentConnection (
365
+ ip = ip ,
366
+ port = port ,
367
+ password = password ,
296
368
channel = channel ,
297
369
cleanup_on_exit = cleanup_on_exit ,
298
370
remote_instance = instance ,
0 commit comments