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 inSilaServer.add_feature_implementation - add property
__stop_event = threading.Event() - add method
run_periodically(func: Callable[[], None], delay_seconds: float) -> Nonethat contains an inner function which callsfunc()andtime.sleep(delay_seconds)untilself.__stop_eventis set (poll every 0.1 seconds to ensure server shutdown does not takedelay_seconds). This inner function is then executed viaself.parent_server.child_task_executor.submit. - call
self.__stop_event.set()inself.stop() - document that
super().start()must be called if theImplclass overrides thestartmethod