Skip to content

Commit e8f9284

Browse files
AlexTatemr-c
authored andcommitted
Changing TaskQueue constructor to accept the kill_switch threading.Event as an argument rather than an entire RuntimeContext, per @mr-c
1 parent 20fd703 commit e8f9284

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

cwltool/executors.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def check_for_abstract_op(tool: CWLObjectType) -> None:
102102
runtime_context.mutation_manager = MutationManager()
103103
runtime_context.toplevel = True
104104
runtime_context.workflow_eval_lock = threading.Condition(threading.RLock())
105+
runtime_context.kill_switch = threading.Event()
105106

106107
job_reqs: Optional[list[CWLObjectType]] = None
107108
if "https://w3id.org/cwl/cwl#requirements" in job_order_object:
@@ -439,9 +440,13 @@ def run_jobs(
439440
logger: logging.Logger,
440441
runtime_context: RuntimeContext,
441442
) -> None:
443+
if runtime_context.kill_switch is None:
444+
runtime_context.kill_switch = threading.Event()
445+
442446
self.taskqueue: TaskQueue = TaskQueue(
443-
threading.Lock(), int(math.ceil(self.max_cores)), runtime_context
447+
threading.Lock(), int(math.ceil(self.max_cores)), runtime_context.kill_switch
444448
)
449+
445450
try:
446451
jobiter = process.job(job_order_object, self.output_callback, runtime_context)
447452

cwltool/task_queue.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import threading
88
from typing import Callable, Optional
99

10-
from .context import RuntimeContext
1110
from .errors import WorkflowKillSwitch
1211
from .loghandler import _logger
1312

@@ -35,7 +34,7 @@ class TaskQueue:
3534
in_flight: int = 0
3635
"""The number of tasks in the queue."""
3736

38-
def __init__(self, lock: threading.Lock, thread_count: int, runtime_context: RuntimeContext):
37+
def __init__(self, lock: threading.Lock, thread_count: int, kill_switch: threading.Event):
3938
"""Create a new task queue using the specified lock and number of threads."""
4039
self.thread_count = thread_count
4140
self.task_queue: queue.Queue[Optional[Callable[[], None]]] = queue.Queue(
@@ -44,11 +43,7 @@ def __init__(self, lock: threading.Lock, thread_count: int, runtime_context: Run
4443
self.task_queue_threads = []
4544
self.lock = lock
4645
self.error: Optional[BaseException] = None
47-
48-
if runtime_context.kill_switch is None:
49-
self.kill_switch = runtime_context.kill_switch = threading.Event()
50-
else:
51-
self.kill_switch = runtime_context.kill_switch
46+
self.kill_switch = kill_switch
5247

5348
for _r in range(0, self.thread_count):
5449
t = threading.Thread(target=self._task_queue_func)

0 commit comments

Comments
 (0)