@@ -341,6 +341,7 @@ def stderr_stdout_log_path(
341
341
env = env ,
342
342
cwd = self .outdir ,
343
343
make_job_dir = lambda : runtimeContext .create_outdir (),
344
+ kill_switch = runtimeContext .kill_switch ,
344
345
job_script_contents = job_script_contents ,
345
346
timelimit = self .timelimit ,
346
347
name = self .name ,
@@ -506,8 +507,8 @@ def prepare_environment(
506
507
# Set on ourselves
507
508
self .environment = env
508
509
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 ."""
511
512
monitor = psutil .Process (sproc .pid )
512
513
# Value must be list rather than integer to utilise pass-by-reference in python
513
514
memory_usage : MutableSequence [Optional [int ]] = [None ]
@@ -849,6 +850,7 @@ def docker_monitor(
849
850
cleanup_cidfile : bool ,
850
851
docker_exe : str ,
851
852
process : "subprocess.Popen[str]" ,
853
+ kill_switch : threading .Event ,
852
854
) -> None :
853
855
"""Record memory usage of the running Docker container."""
854
856
# Todo: consider switching to `docker create` / `docker start`
@@ -925,6 +927,7 @@ def _job_popen(
925
927
env : Mapping [str , str ],
926
928
cwd : str ,
927
929
make_job_dir : Callable [[], str ],
930
+ kill_switch : threading .Event ,
928
931
job_script_contents : Optional [str ] = None ,
929
932
timelimit : Optional [int ] = None ,
930
933
name : Optional [str ] = None ,
0 commit comments