@@ -90,26 +90,19 @@ def _verify_ansys_path_is_valid(ansys_path, executable, path_in_install = None):
9090
9191
9292def _run_launch_server_process (ansys_path , ip , port , docker_name ):
93+ bShell = False
9394 if docker_name :
9495 docker_server_port = int (os .environ .get ("DOCKER_SERVER_PORT" , port ))
9596 dpf_run_dir = os .getcwd ()
9697 from ansys .dpf .core import LOCAL_DOWNLOADED_EXAMPLES_PATH
97- if os .name == "nt" :
98- run_cmd = f"docker run -d -p { port } :{ docker_server_port } " \
99- f"{ RUNNING_DOCKER ['args' ]} " \
100- f'-v "{ LOCAL_DOWNLOADED_EXAMPLES_PATH } :/tmp/downloaded_examples" ' \
101- f"-e DOCKER_SERVER_PORT={ docker_server_port } " \
102- f"--expose={ docker_server_port } " \
103- f"{ docker_name } "
104- else :
105- run_cmd = ["docker run" ,
106- "-d" ,
107- f"-p" + f"{ port } :{ docker_server_port } " ,
108- RUNNING_DOCKER ['args' ],
109- f'-v "{ LOCAL_DOWNLOADED_EXAMPLES_PATH } :/tmp/downloaded_examples"'
110- f"-e DOCKER_SERVER_PORT={ docker_server_port } " ,
111- f"--expose={ docker_server_port } " ,
112- docker_name ]
98+ if os .name == "posix" :
99+ bShell = True
100+ run_cmd = f"docker run -d -p { port } :{ docker_server_port } " \
101+ f"{ RUNNING_DOCKER ['args' ]} " \
102+ f'-v "{ LOCAL_DOWNLOADED_EXAMPLES_PATH } :/tmp/downloaded_examples" ' \
103+ f"-e DOCKER_SERVER_PORT={ docker_server_port } " \
104+ f"--expose={ docker_server_port } " \
105+ f"{ docker_name } "
113106 else :
114107 if os .name == "nt" :
115108 executable = "Ans.Dpf.Grpc.bat"
@@ -122,7 +115,10 @@ def _run_launch_server_process(ansys_path, ip, port, docker_name):
122115
123116 old_dir = os .getcwd ()
124117 os .chdir (dpf_run_dir )
125- process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
118+ if not bShell :
119+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
120+ else :
121+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
126122 os .chdir (old_dir )
127123 return process
128124
@@ -153,8 +149,23 @@ def launch_dpf(ansys_path, ip=LOCALHOST, port=DPF_DEFAULT_PORT, timeout=10, dock
153149 process : subprocess.Popen
154150 DPF Process.
155151 """
152+ from ansys .dpf .core .server import port_in_use
153+
156154 process = _run_launch_server_process (ansys_path , ip , port , docker_name )
157155
156+ if docker_name is not None and os .name == 'posix' :
157+ run_cmd = "docker ps --all"
158+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
159+ used_ports = []
160+ for line in io .TextIOWrapper (process .stdout , encoding = "utf-8" ):
161+ if not ("CONTAINER ID" in line ):
162+ split = line .split ("0.0.0.0:" )
163+ if len (split ) > 1 :
164+ used_port = int (split [1 ].split ("-" )[0 ])
165+ if used_port == port :
166+ docker_id = split [0 ].split (" " )[0 ]
167+ return docker_id
168+
158169 # check to see if the service started
159170 lines = []
160171 docker_id = []
@@ -832,17 +843,26 @@ def info(self):
832843
833844 def shutdown (self ):
834845 if self ._own_process and self .live :
846+ bShell = False
847+ if os .name == 'posix' :
848+ bShell = True
835849 try :
836850 self ._preparing_shutdown_func [0 ](self ._preparing_shutdown_func [1 ])
837851 except Exception as e :
838852 warnings .warn ("couldn't prepare shutdown: " + str (e .args ))
839853 if self .on_docker :
840854 run_cmd = f"docker stop { self ._server_id } "
841- process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
855+ if bShell :
856+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
857+ else :
858+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
842859 run_cmd = f"docker rm { self ._server_id } "
843860 for line in io .TextIOWrapper (process .stdout , encoding = "utf-8" ):
844861 pass
845- process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
862+ if bShell :
863+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE , shell = True )
864+ else :
865+ process = subprocess .Popen (run_cmd , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
846866 elif self ._remote_instance :
847867 self ._remote_instance .delete ()
848868 else :
0 commit comments