20
20
from ansys .dpf .core .misc import find_ansys , is_ubuntu
21
21
from ansys .dpf .core import errors
22
22
23
- from ansys .dpf .core ._version import __ansys_version__
23
+ from ansys .dpf .core ._version import (
24
+ __ansys_version__ ,
25
+ server_to_ansys_version ,
26
+ server_to_ansys_grpc_dpf_version
27
+ )
24
28
from ansys .dpf .core import session
29
+ import ansys .grpc .dpf
25
30
26
31
MAX_PORT = 65535
27
32
@@ -326,6 +331,7 @@ def __init__(
326
331
docker_name = None ,
327
332
):
328
333
"""Start the DPF server."""
334
+
329
335
# check valid ip and port
330
336
check_valid_ip (ip )
331
337
if not isinstance (port , int ):
@@ -338,35 +344,23 @@ def __init__(
338
344
339
345
self .channel = grpc .insecure_channel ("%s:%d" % (ip , port ))
340
346
341
- if launch_server is False :
342
- state = grpc .channel_ready_future (self .channel )
343
- # verify connection has matured
344
- tstart = time .time ()
345
- while ((time .time () - tstart ) < timeout ) and not state ._matured :
346
- time .sleep (0.001 )
347
-
348
- if not state ._matured :
349
- raise TimeoutError (
350
- f"Failed to connect to { ip } :{ port } in { timeout } seconds"
351
- )
352
-
353
- LOG .debug ("Established connection to DPF gRPC" )
354
-
355
347
# assign to global channel when requested
356
348
if as_global :
357
349
dpf .core .SERVER = self
358
350
359
351
# TODO: add to PIDs ...
360
352
361
353
# store port and ip for later reference
362
- self .live = True
363
- self .ansys_path = ansys_path
364
354
self ._input_ip = ip
365
355
self ._input_port = port
356
+ self .live = True
357
+ self .ansys_path = ansys_path
366
358
self ._own_process = launch_server
367
359
self ._base_service_instance = None
368
360
self ._session_instance = None
369
361
362
+ check_ansys_grpc_dpf_version (self , timeout )
363
+
370
364
@property
371
365
def _base_service (self ):
372
366
if not self ._base_service_instance :
@@ -654,3 +648,30 @@ def read_stderr():
654
648
655
649
if len (docker_id ) > 0 :
656
650
return docker_id [0 ]
651
+
652
+
653
+ def check_ansys_grpc_dpf_version (server , timeout ):
654
+ state = grpc .channel_ready_future (server .channel )
655
+ # verify connection has matured
656
+ tstart = time .time ()
657
+ while ((time .time () - tstart ) < timeout ) and not state ._matured :
658
+ time .sleep (0.001 )
659
+
660
+ if not state ._matured :
661
+ raise TimeoutError (
662
+ f"Failed to connect to { server ._input_ip } :{ server ._input_port } in { timeout } seconds"
663
+ )
664
+
665
+ LOG .debug ("Established connection to DPF gRPC" )
666
+ grpc_module_version = ansys .grpc .dpf .__version__
667
+ server_version = server .version
668
+ right_grpc_module_version = server_to_ansys_grpc_dpf_version .get (server_version , None )
669
+ if right_grpc_module_version and right_grpc_module_version != grpc_module_version :
670
+ raise ImportWarning (f"2022R1 Ansys unified install is available. "
671
+ f"To use DPF server from Ansys "
672
+ f"{ server_to_ansys_version .get (server_version , 'Unknown' )} "
673
+ f" (dpf.SERVER.version=='{ server_version } '), "
674
+ f"install version { right_grpc_module_version } of ansys-grpc-dpf"
675
+ f" with the command: \n "
676
+ f" pip install ansys-grpc-dpf=={ right_grpc_module_version } "
677
+ )
0 commit comments