mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-04 04:40:39 +02:00
moves autostart from Task to separate autostart submodule
This commit is contained in:
parent
416b9ee815
commit
bfa0acedab
15
src/pydase/task/autostart.py
Normal file
15
src/pydase/task/autostart.py
Normal file
@ -0,0 +1,15 @@
|
||||
import pydase.data_service.data_service
|
||||
import pydase.task.task
|
||||
from pydase.utils.helpers import is_property_attribute
|
||||
|
||||
|
||||
def autostart_service_tasks(
|
||||
service: pydase.data_service.data_service.DataService,
|
||||
) -> None:
|
||||
for attr in dir(service):
|
||||
if not is_property_attribute(service, attr): # prevent eval of property attrs
|
||||
val = getattr(service, attr)
|
||||
if isinstance(val, pydase.task.task.Task) and val.autostart:
|
||||
val.start()
|
||||
elif isinstance(val, pydase.DataService):
|
||||
autostart_service_tasks(val)
|
@ -57,6 +57,12 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
||||
self._status = TaskStatus.NOT_RUNNING
|
||||
self._result: R | None = None
|
||||
|
||||
@property
|
||||
def autostart(self) -> bool:
|
||||
"""Defines if the task should be started automatically when the `pydase.Server`
|
||||
starts."""
|
||||
return self._autostart
|
||||
|
||||
@property
|
||||
def status(self) -> TaskStatus:
|
||||
return self._status
|
||||
@ -129,7 +135,4 @@ class Task(pydase.data_service.data_service.DataService, Generic[R]):
|
||||
self._loop = asyncio.get_event_loop()
|
||||
self._bound_func = self._func.__get__(instance, owner)
|
||||
self._set_up = True
|
||||
|
||||
if self._autostart:
|
||||
self.start()
|
||||
return self
|
||||
|
Loading…
x
Reference in New Issue
Block a user