@@ -231,7 +231,9 @@ def _execute(
231231 runtime : List [str ],
232232 env : MutableMapping [str , str ],
233233 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 ,
235237 ) -> None :
236238 """Execute the tool, either directly or via script.
237239
@@ -333,6 +335,10 @@ def stderr_stdout_log_path(
333335 builder : Optional [Builder ] = getattr (self , "builder" , None )
334336 if builder is not None :
335337 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
336342 rcode = _job_popen (
337343 commands ,
338344 stdin_path = stdin_path ,
@@ -341,7 +347,7 @@ def stderr_stdout_log_path(
341347 env = env ,
342348 cwd = self .outdir ,
343349 make_job_dir = lambda : runtimeContext .create_outdir (),
344- kill_switch = runtimeContext . kill_switch ,
350+ kill_switch = kill_switch ,
345351 job_script_contents = job_script_contents ,
346352 timelimit = self .timelimit ,
347353 name = self .name ,
@@ -547,7 +553,8 @@ def monitor_kill_switch() -> None:
547553 nonlocal ks_tm
548554 if kill_switch .is_set ():
549555 _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 ()
551558 sproc .terminate ()
552559 else :
553560 ks_tm = Timer (interval = 1 , function = monitor_kill_switch )
0 commit comments