1111import os
1212import queue
1313import shutil
14+ import signal
1415import socket
1516import subprocess
1617import sys
@@ -175,7 +176,7 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
175176 f'DVM environment variable PMIX_SERVER_URI41 set in os.environ to { os .environ ["PMIX_SERVER_URI41" ]} '
176177 )
177178
178- timeout = float (kwargs . get ( 'timeout' , 1.0e9 ))
179+ timeout = float (kwargs [ 'timeout' ]) if 'timeout' in kwargs else None
179180
180181 cmd = f'{ executable } { " " .join (map (str , args ))} '
181182
@@ -193,6 +194,7 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
193194
194195 cmd_lst = cmd .split ()
195196 process = None
197+ out , err = None , None
196198 try :
197199 try :
198200 process = subprocess .Popen (
@@ -201,7 +203,7 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
201203 stderr = subprocess_stderr ,
202204 cwd = working_dir_path ,
203205 text = True ,
204- preexec_fn = os . setsid , # noqa: PLW1509 # TODO - FIX THIS, it is deprecated (https://github.com/python/cpython/issues/82616) (https://docs.astral.sh/ruff/rules/subprocess-popen-preexec-fn/)
206+ start_new_session = True ,
205207 env = new_env ,
206208 )
207209 except Exception as e :
@@ -219,7 +221,9 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
219221 raise
220222
221223 try :
222- ret_val = process .wait (timeout )
224+ # communicate() drains the pipes while waiting; wait() deadlocks once a PIPE fills
225+ out , err = process .communicate (timeout = timeout )
226+ ret_val = process .returncode
223227 finish_time = time .time ()
224228 worker .log_event (
225229 'ips' ,
@@ -245,7 +249,9 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
245249 'comment' : f'task_name = { task_name } , timed-out after { timeout } s' ,
246250 },
247251 )
248- process .kill ()
252+ # child is a session leader (setsid); kill the whole group so no grandchild keeps the pipe open
253+ os .killpg (process .pid , signal .SIGKILL )
254+ out , err = process .communicate ()
249255 log .error (f'Task { task_name } with command { cmd } timed out after { timeout } s' )
250256 ret_val = - 1
251257 except Exception as e :
@@ -260,10 +266,10 @@ def launch(executable: Any, task_name: str, working_dir: str | os.PathLike, *arg
260266 )
261267 log .error (f'Task { task_name } with command { cmd } failed with { e !s} ' )
262268 finally :
263- if 'logfile' not in kwargs :
264- print (process . stdout . read () if process and process . stdout else '' )
265- if 'errfile' not in kwargs :
266- print (process . stderr . read () if process and process . stderr else '' , file = sys .stderr )
269+ if out :
270+ print (out )
271+ if err :
272+ print (err , file = sys .stderr )
267273
268274 if close_stdout :
269275 subprocess_stdout .close ()
@@ -3257,10 +3263,11 @@ def setup(self, worker: Worker):
32573263 # 253-dvm-daemons-should-be-in-scheduler-plugin and just needs
32583264 # vetting.
32593265 command = [
3260- 'prte' ,
3261- '--host' , 'localhost' ,
3262- '--report-uri' ,
3263- self .worker .dvm_uri_file ,
3266+ 'prte' ,
3267+ '--host' ,
3268+ 'localhost' ,
3269+ '--report-uri' ,
3270+ self .worker .dvm_uri_file ,
32643271 ]
32653272
32663273 mapping_policy = 'core' # by default bind to cores
@@ -3642,8 +3649,9 @@ def _make_worker_args(
36423649 raise
36433650
36443651 dask_nodes = 1 if dask_nodes is None else dask_nodes
3645- self .services .info (f'Launching { dask_nodes } Dask workers with '
3646- f'{ dask_ppw } processes per worker' )
3652+ self .services .info (
3653+ f'Launching { dask_nodes } Dask workers with { dask_ppw } processes per worker'
3654+ )
36473655 # if services.get_config_param('MPIRUN') == 'eval':
36483656 # # TODO Why?
36493657 # Commenting this out for now since it seems to be a hack that is no
0 commit comments