Skip to content

Commit 2e0107f

Browse files
committed
restructure
1 parent 1740dfc commit 2e0107f

4 files changed

Lines changed: 12 additions & 37 deletions

File tree

executorlib/executor/flux.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,6 @@ def __init__(
360360
create_file_executor,
361361
)
362362

363-
from executorlib.task_scheduler.file.queue_spawner import (
364-
get_terminate_function,
365-
)
366-
367-
terminate_function = get_terminate_function(
368-
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
369-
)
370-
371363
super().__init__(
372364
executor=create_file_executor(
373365
max_workers=max_workers,
@@ -384,7 +376,7 @@ def __init__(
384376
block_allocation=block_allocation,
385377
init_function=init_function,
386378
disable_dependencies=disable_dependencies,
387-
terminate_function=terminate_function,
379+
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown,
388380
)
389381
)
390382
else:

executorlib/executor/slurm.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,6 @@ def __init__(
166166
create_file_executor,
167167
)
168168

169-
from executorlib.task_scheduler.file.queue_spawner import (
170-
get_terminate_function,
171-
)
172-
173-
terminate_function = get_terminate_function(
174-
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
175-
)
176-
177169
super().__init__(
178170
executor=create_file_executor(
179171
max_workers=max_workers,
@@ -190,7 +182,7 @@ def __init__(
190182
block_allocation=block_allocation,
191183
init_function=init_function,
192184
disable_dependencies=disable_dependencies,
193-
terminate_function=terminate_function,
185+
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown,
194186
)
195187
)
196188
else:

executorlib/task_scheduler/file/queue_spawner.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,3 @@ def _pysqa_execute_command(
138138
return out.split("\n")
139139
else:
140140
return out
141-
142-
143-
def get_terminate_function(terminate_tasks_on_shutdown: bool) -> Optional[Callable]:
144-
"""
145-
Get the appropriate terminate function based on the shutdown configuration.
146-
147-
Args:
148-
terminate_tasks_on_shutdown (bool): Flag indicating whether to terminate tasks on shutdown.
149-
150-
Returns:
151-
Optional[Callable]: The terminate function to use, or None if no termination is needed.
152-
"""
153-
if terminate_tasks_on_shutdown:
154-
return terminate_with_pysqa
155-
else:
156-
return None

executorlib/task_scheduler/file/task_scheduler.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
from executorlib.task_scheduler.base import TaskSchedulerBase
1313
from executorlib.task_scheduler.file.shared import execute_tasks_h5
1414
from executorlib.task_scheduler.file.subprocess_spawner import (
15-
execute_in_subprocess,
15+
execute_in_subprocess, terminate_subprocess
1616
)
1717

1818
try:
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
2020
except 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

2526
class 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

Comments
 (0)