@@ -231,7 +231,9 @@ def _execute(
231
231
runtime : List [str ],
232
232
env : MutableMapping [str , str ],
233
233
runtimeContext : RuntimeContext ,
234
- monitor_function : Optional [Callable [["subprocess.Popen[str]" ], None ]] = None ,
234
+ monitor_function : Optional [
235
+ Callable [["subprocess.Popen[str]" , threading .Event ], None ]
236
+ ] = None ,
235
237
) -> None :
236
238
"""Execute the tool, either directly or via script.
237
239
@@ -333,6 +335,10 @@ def stderr_stdout_log_path(
333
335
builder : Optional [Builder ] = getattr (self , "builder" , None )
334
336
if builder is not None :
335
337
job_script_contents = builder .build_job_script (commands )
338
+ if runtimeContext .kill_switch is None :
339
+ runtimeContext .kill_switch = kill_switch = threading .Event ()
340
+ else :
341
+ kill_switch = runtimeContext .kill_switch
336
342
rcode = _job_popen (
337
343
commands ,
338
344
stdin_path = stdin_path ,
@@ -341,7 +347,7 @@ def stderr_stdout_log_path(
341
347
env = env ,
342
348
cwd = self .outdir ,
343
349
make_job_dir = lambda : runtimeContext .create_outdir (),
344
- kill_switch = runtimeContext . kill_switch ,
350
+ kill_switch = kill_switch ,
345
351
job_script_contents = job_script_contents ,
346
352
timelimit = self .timelimit ,
347
353
name = self .name ,
@@ -547,7 +553,8 @@ def monitor_kill_switch() -> None:
547
553
nonlocal ks_tm
548
554
if kill_switch .is_set ():
549
555
_logger .error ("[job %s] terminating by kill switch" , self .name )
550
- if sproc .stdin : sproc .stdin .close ()
556
+ if sproc .stdin :
557
+ sproc .stdin .close ()
551
558
sproc .terminate ()
552
559
else :
553
560
ks_tm = Timer (interval = 1 , function = monitor_kill_switch )
0 commit comments