fixing circular import

This commit is contained in:
Mose Müller 2024-08-19 17:21:14 +02:00
parent fa35fa53e2
commit d1d2ac2614
5 changed files with 11 additions and 16 deletions

View File

@ -1,7 +1,7 @@
import asyncio import asyncio
import pydase.data_service import pydase.data_service
import pydase.task import pydase.task.decorator
class DeviceConnection(pydase.data_service.DataService): class DeviceConnection(pydase.data_service.DataService):
@ -70,7 +70,7 @@ class DeviceConnection(pydase.data_service.DataService):
""" """
return self._connected return self._connected
@pydase.task.task(autostart=True) @pydase.task.decorator.task(autostart=True)
async def _handle_connection(self) -> None: async def _handle_connection(self) -> None:
"""Automatically tries reconnecting to the device if it is not connected. """Automatically tries reconnecting to the device if it is not connected.
This method leverages the `connect` method and the `connected` property to This method leverages the `connect` method and the `connected` property to

View File

@ -1,3 +0,0 @@
from pydase.task.decorator import task
__all__ = ["task"]

View File

@ -3,7 +3,6 @@ import inspect
import logging import logging
import sys import sys
from collections.abc import Callable, Coroutine from collections.abc import Callable, Coroutine
from enum import Enum
from typing import ( from typing import (
Any, Any,
Generic, Generic,
@ -12,6 +11,8 @@ from typing import (
from typing_extensions import TypeIs from typing_extensions import TypeIs
from pydase.task.task_status import TaskStatus
if sys.version_info < (3, 11): if sys.version_info < (3, 11):
from typing_extensions import Self from typing_extensions import Self
else: else:
@ -34,11 +35,6 @@ def is_bound_method(
return inspect.ismethod(method) return inspect.ismethod(method)
class TaskStatus(Enum):
RUNNING = "running"
NOT_RUNNING = "not_running"
class Task(pydase.data_service.data_service.DataService, Generic[R]): class Task(pydase.data_service.data_service.DataService, Generic[R]):
def __init__( def __init__(
self, self,

View File

@ -0,0 +1,6 @@
import enum
class TaskStatus(enum.Enum):
RUNNING = "running"
NOT_RUNNING = "not_running"

View File

@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any, Literal, cast
import pydase.units as u import pydase.units as u
from pydase.data_service.abstract_data_service import AbstractDataService from pydase.data_service.abstract_data_service import AbstractDataService
from pydase.task.task import TaskStatus from pydase.task.task_status import TaskStatus
from pydase.utils.decorators import render_in_frontend from pydase.utils.decorators import render_in_frontend
from pydase.utils.helpers import ( from pydase.utils.helpers import (
get_attribute_doc, get_attribute_doc,
@ -310,10 +310,6 @@ class Serializer:
path = f"{access_path}.{key}" if access_path else key path = f"{access_path}.{key}" if access_path else key
serialized_object = cls.serialize_object(val, access_path=path) serialized_object = cls.serialize_object(val, access_path=path)
# If there's a running task for this method
if serialized_object["type"] == "method" and key in obj._task_manager.tasks:
serialized_object["value"] = TaskStatus.RUNNING.name
value[key] = serialized_object value[key] = serialized_object
# If the DataService attribute is a property # If the DataService attribute is a property