also create start, stop and wait function in task_producer

This commit is contained in:
2021-10-27 12:07:31 +02:00
parent 70721ed536
commit 7dc5eaba7c
2 changed files with 21 additions and 10 deletions
+4 -1
View File
@@ -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):
+17 -9
View File
@@ -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()