@@ -341,6 +341,7 @@ def stderr_stdout_log_path(
341341 env = env ,
342342 cwd = self .outdir ,
343343 make_job_dir = lambda : runtimeContext .create_outdir (),
344+ kill_switch = runtimeContext .kill_switch ,
344345 job_script_contents = job_script_contents ,
345346 timelimit = self .timelimit ,
346347 name = self .name ,
@@ -506,8 +507,8 @@ def prepare_environment(
506507 # Set on ourselves
507508 self .environment = env
508509
509- def process_monitor (self , sproc : "subprocess.Popen[str]" ) -> None :
510- """Watch a process, logging its max memory usage."""
510+ def process_monitor (self , sproc : "subprocess.Popen[str]" , kill_switch : threading . Event ) -> None :
511+ """Watch a process, logging its max memory usage or terminating it if kill_switch is activated ."""
511512 monitor = psutil .Process (sproc .pid )
512513 # Value must be list rather than integer to utilise pass-by-reference in python
513514 memory_usage : MutableSequence [Optional [int ]] = [None ]
@@ -849,6 +850,7 @@ def docker_monitor(
849850 cleanup_cidfile : bool ,
850851 docker_exe : str ,
851852 process : "subprocess.Popen[str]" ,
853+ kill_switch : threading .Event ,
852854 ) -> None :
853855 """Record memory usage of the running Docker container."""
854856 # Todo: consider switching to `docker create` / `docker start`
@@ -925,6 +927,7 @@ def _job_popen(
925927 env : Mapping [str , str ],
926928 cwd : str ,
927929 make_job_dir : Callable [[], str ],
930+ kill_switch : threading .Event ,
928931 job_script_contents : Optional [str ] = None ,
929932 timelimit : Optional [int ] = None ,
930933 name : Optional [str ] = None ,
0 commit comments