Unify how classes/objects that spawn tasks should be managed #197
Replies: 3 comments 5 replies
-
Wrt to the class name, I'd suggest something with the prefix
|
Beta Was this translation helpful? Give feedback.
-
Just want to point out that there are scenarios that this doesn't cover, especially when it comes to short-lived tasks, like If there's such a scenario, we won't be able to use So while the proposal does make sense to simplify most use-cases, a common approach might not work in all cases, and we'll still have to implement custom |
Beta Was this translation helpful? Give feedback.
-
I will give this a go: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Right now we have no common approach on how to manage classes/objects that spawn tasks. The most core example are actors, but we also have a lot of other classes that spawn tasks (like the resampler, moving window, etc.).
It should be possible to clearly control the lifespan of these objects, and be able to cleanly and clearly start and stop the tasks they spawn.
For now every class is doing their own thing, sometimes there is no way to stop things, sometimes there is but it is private, etc.
We should have a common way to do this.
Proposal
Add a
Worker
class to the SDK that provides a simple framework to handle this.Here is a quick sketch of a possible implementation:
(
join()
andstop()
should probably be implemented usingasyncio.wait()
in a more resilient way)Then all other classes can inherit from
Worker
:Advantages
Disadvantages
start()
it might take a while to figure out what's going on.Class name
Worker
is not a great name, as it is usually used for something that runs in a thread and can run a task, but I could not think of a better name.I thought of
Task
but it might be confusing givenasyncio.Task
, I thought ofBackgroundTask
as it is something that it is supposed to run in the background, opposed to a generalTask
that can also be some calculation for which you want some result, but want to run several calculations in parallel.I thought of
Daemon
as the functionality is similar to a unix daemon. Or maybeService
in the same sense.References
FYI @frequenz-floss/python-sdk-team
Beta Was this translation helpful? Give feedback.
All reactions