tiqi-group / pydase

A Python library for creating remote control interfaces of Python objects.
https://pydase.readthedocs.io
MIT License
1 stars 1 forks source link

Control of tasks in instances derived from same class only controls task of first instance #160

Closed lmaisenbacherberkeley closed 1 week ago

lmaisenbacherberkeley commented 1 week ago

Describe the bug

When using multiple instances of the same class as sub-DataServices ("channels"), and those channels include a task, all task controls only control the task of one of the channels. E.g., for the case of two channels, starting the task in the second channel sets the status of the task of channel 1 and channel 2 to running, but actually only runs the task in channel 1.

To Reproduce

Using pydase 0.10.2.

import numpy as np
import asyncio

import pydase
from pydase.task.decorator import task
from pydase.utils.decorators import frontend

class Channel(pydase.DataService):

    def __init__(self, description):
        super().__init__()
        self.description : str = description
        self.random_output : float = 0.

    @property
    def task_status(self) -> str:
        """Status of task."""
        return self.my_task.status

    @frontend
    def start_task(self) -> None:
        """Manual start as an additional test."""
        self.my_task.start()

    @task()
    async def my_task(self) -> None:
        while True:
            self.random_output = np.random.rand()
            await asyncio.sleep(1)

class MyService(pydase.DataService):

    def __init__(self):
        super().__init__()

        self.channel_1 = Channel('Channel 1')
        self.channel_2 = Channel('Channel 2')

if __name__ == "__main__":
    service = MyService()
    pydase.Server(service=service).run()

Expected behaviour

An interface for two channels with one task each is generated. Starting the task in each channel leads to an output of a random number in that channel, and does not influence the task in the other channel.

Additional context

This worked with the earlier implementation of tasks in version 0.7.4 (with the appropriate changes in how tasks are defined).

mosmuell commented 1 week ago

Alright! Thanks for the report. More thorough testing is in place then ;) I'll have a look right now.

mosmuell commented 1 week ago

This was a tricky one. Should be fixed in v0.10.3, though.

lmaisenbacherberkeley commented 6 days ago

Great, thanks, the behavior is now as expected.