1212from executorlib .task_scheduler .base import TaskSchedulerBase
1313from executorlib .task_scheduler .file .shared import execute_tasks_h5
1414from executorlib .task_scheduler .file .subprocess_spawner import (
15- execute_in_subprocess ,
15+ execute_in_subprocess , terminate_subprocess
1616)
1717
1818try :
19- from executorlib .task_scheduler .file .queue_spawner import execute_with_pysqa
19+ from executorlib .task_scheduler .file .queue_spawner import execute_with_pysqa , terminate_with_pysqa
2020except ImportError :
2121 # If pysqa is not available fall back to executing tasks in a subprocess
2222 execute_with_pysqa = execute_in_subprocess # type: ignore
23+ terminate_with_pysqa = None
2324
2425
2526class FileTaskScheduler (TaskSchedulerBase ):
@@ -90,7 +91,7 @@ def create_file_executor(
9091 init_function : Optional [Callable ] = None ,
9192 disable_dependencies : bool = False ,
9293 execute_function : Callable = execute_with_pysqa ,
93- terminate_function : Optional [ Callable ] = None ,
94+ terminate_tasks_on_shutdown : bool = True ,
9495):
9596 if block_allocation :
9697 raise ValueError (
@@ -108,6 +109,12 @@ def create_file_executor(
108109 check_executor (executor = flux_executor )
109110 check_nested_flux_executor (nested_flux_executor = flux_executor_nesting )
110111 check_flux_log_files (flux_log_files = flux_log_files )
112+ if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess :
113+ terminate_function = terminate_with_pysqa
114+ elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess :
115+ terminate_function = terminate_subprocess
116+ else :
117+ terminate_function = None
111118 return FileTaskScheduler (
112119 resource_dict = resource_dict ,
113120 pysqa_config_directory = pysqa_config_directory ,
0 commit comments