Allow servers to run functions periodically

It would be great if the following would work in Impl classes:

class MyFeatureImpl(FeatureImplementationBase):
    ...

    def start(self):
        self.run_periodically(self.update_MyProperty(...), delay_seconds=0.1)

Implementation idea (in Base classes):

  • add property parent_server, set it in SilaServer.add_feature_implementation
  • add property __stop_event = threading.Event()
  • add method run_periodically(func: Callable[[], None], delay_seconds: float) -> None that contains an inner function which calls func() and time.sleep(delay_seconds) until self.__stop_event is set (poll every 0.1 seconds to ensure server shutdown does not take delay_seconds). This inner function is then executed via self.parent_server.child_task_executor.submit.
  • call self.__stop_event.set() in self.stop()
  • document that super().start() must be called if the Impl class overrides the start method
Assignee Loading
Time tracking Loading