zauberzeug / rosys

An all-Python robot system based on web technologies. The purpose is similar to ROS, but it's based on NiceGUI and easier to use for mobile robotics.
https://rosys.io
MIT License
70 stars 10 forks source link

Support tracking multiple tasks #148

Closed falkoschindler closed 2 months ago

falkoschindler commented 2 months ago

Similar to NiceGUI's slot stacks, this PR implements separate @track stacks per task ID. Originally this was meant to solve issue #147, but it turned out that parallelized coroutines share the same task ID. Nevertheless, this PR should prevent the track stack from getting scrambled when calling tracked coroutines from different tasks, e.g. by clicking UI buttons.

falkoschindler commented 2 months ago

I just merged this PR with the new implementation #150 and successfully tested with the following demo:

from nicegui import ui
import rosys

@rosys.analysis.track
async def short():
    await rosys.sleep(0.25)

@rosys.analysis.track
async def long():
    await rosys.sleep(0.75)

@rosys.analysis.track
async def run() -> None:
    await rosys.automation.parallelize(short(), long())

automator1 = rosys.automation.Automator(None, default_automation=run)
automator2 = rosys.automation.Automator(None, default_automation=run)

rosys.automation.automation_controls(automator1)
rosys.automation.automation_controls(automator2)
rosys.analysis.track.ui()

ui.run()