From 7dc5eaba7ccd0729ad49579348ea45189c238615 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Wed, 27 Oct 2021 12:07:31 +0200 Subject: [PATCH] also create start, stop and wait function in task_producer --- slic/core/adjustable/adjustable.py | 5 ++++- slic/core/task/tools.py | 26 +++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/slic/core/adjustable/adjustable.py b/slic/core/adjustable/adjustable.py index be34eb459..8a4af2c5a 100644 --- a/slic/core/adjustable/adjustable.py +++ b/slic/core/adjustable/adjustable.py @@ -6,13 +6,16 @@ from .convenience import SpecConvenience class Adjustable(BaseAdjustable, TaskProducer, SpecConvenience): + stop = None + def __init__(self, ID, name=None, units=None, internal=False): self.ID = ID self.name = name or ID self.units = units self.internal = internal - self.set_target_value = self.task_producer(self.set_target_value) + self.set_target_value, _start, self.stop, self.wait =\ + self.task_producer(self.set_target_value, stopper=self.stop) def tweak(self, delta, *args, **kwargs): diff --git a/slic/core/task/tools.py b/slic/core/task/tools.py index cbebff8ad..462d9889e 100644 --- a/slic/core/task/tools.py +++ b/slic/core/task/tools.py @@ -5,27 +5,35 @@ from .task import Task class TaskProducer: + #TODO: allow more than one current_task? current_task = None + def task_producer(self, func, starter=None, stopper=None): @forwards_to(func, nfilled=1) # nfilled=1 to remove self @wraps(func) def wrapper(*args, hold=False, **kwargs): filled_func = lambda: func(*args, **kwargs) return self._as_task(filled_func, starter=starter, stopper=stopper, hold=hold) - return wrapper + + def task_start(): + if self.current_task: + return self.current_task.start() + + def task_stop(): + if self.current_task: + return self.current_task.stop() + + def task_wait(self): + if self.current_task: + return self.current_task.wait() + + return wrapper, task_start, task_stop, task_wait + def _as_task(self, *args, **kwargs): self.current_task = task = Task(*args, **kwargs) return task - def wait(self): - if self.current_task: - return self.current_task.wait() - - def stop(self): - if self.current_task: - return self.current_task.stop() -