7878modules = [tup [1 ] for tup in pkgutil .iter_modules ()]
7979
8080
81+ def grpc_server_on (channel , timeout_sec = 5 ) -> bool :
82+ try :
83+ grpc_channel = grpc .insecure_channel (channel )
84+ grpc .channel_ready_future (grpc_channel ).result (timeout_sec )
85+ return True
86+ except grpc .FutureTimeoutError : # pragma: no cover
87+ return False
88+
89+
8190@pyaedt_function_handler ()
82- def launch_aedt (full_path , non_graphical , port , student_version , first_run = True ):
91+ def launch_aedt (full_path , non_graphical , port , student_version , first_run = True ): # pragma: no cover
8392 """Launch AEDT in gRPC mode."""
8493
8594 def launch_desktop_on_port ():
@@ -90,29 +99,21 @@ def launch_desktop_on_port():
9099 command .append ("-waitforlicense" )
91100 if settings .aedt_log_file :
92101 command .extend (["-Logfile" , settings .aedt_log_file ])
93- my_env = os .environ .copy ()
94- for env , val in settings .aedt_environment_variables .items ():
95- my_env [env ] = val
102+
96103 if is_linux : # pragma: no cover
97104 command .append ("&" )
98- subprocess .Popen (
99- command , env = my_env , stdin = subprocess .DEVNULL , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL
100- )
105+ subprocess .Popen (command , stdin = subprocess .DEVNULL , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
101106 else :
102107 subprocess .Popen (
103108 " " .join (command ),
104- env = my_env ,
105109 stdin = subprocess .DEVNULL ,
106110 stdout = subprocess .DEVNULL ,
107111 stderr = subprocess .DEVNULL ,
108112 creationflags = subprocess .DETACHED_PROCESS ,
109113 )
110114
111- import threading
115+ launch_desktop_on_port ()
112116
113- _aedt_process_thread = threading .Thread (target = launch_desktop_on_port )
114- _aedt_process_thread .daemon = True
115- _aedt_process_thread .start ()
116117 on_ci = os .getenv ("ON_CI" , "False" )
117118 if not student_version and on_ci != "True" and not settings .skip_license_check :
118119 available_licenses = available_license_feature ()
@@ -1177,9 +1178,7 @@ def _init_grpc(self, non_graphical, new_aedt_session, version, student_version,
11771178 installer = Path (settings .aedt_install_dir ) / "ansysedtsv.exe"
11781179 else :
11791180 installer = Path (settings .aedt_install_dir ) / "ansysedt.exe"
1180-
11811181 out , self .port = launch_aedt (installer , non_graphical , self .port , student_version )
1182- self .launched_by_pyaedt = True
11831182 oApp = self ._initialize (
11841183 is_grpc = True ,
11851184 non_graphical = non_graphical ,
@@ -1188,6 +1187,10 @@ def _init_grpc(self, non_graphical, new_aedt_session, version, student_version,
11881187 new_session = not out ,
11891188 version = version_key ,
11901189 )
1190+ self .launched_by_pyaedt = True if oApp else False
1191+ if not self .launched_by_pyaedt : # pragma: no cover
1192+ self .logger .error ("Failed to connect to AEDT using gRPC plugin." )
1193+ self .logger .error ("Check installation, license and environment variables." )
11911194 else :
11921195 oApp = self ._initialize (
11931196 is_grpc = True ,
0 commit comments