Commit e67d2bf2 authored by david's avatar david
Browse files

Parent:child dependency using join(). #62

parent 019f014d
Pipeline #909 passed with stage
in 5 minutes and 4 seconds
......@@ -248,14 +248,19 @@ class EngineExecutor(Timer):
self.start()
def on_ready(self, func):
"""
Calls the passed function `func` when the timer is ready.
"""
self.join()
func()
def wait_for_parent(self):
"""
Child timers are dependend on their parents. So let's wait until parents are done with their stuff.
"""
if self.parent_timer:
# Wait a bit to allow any parent to complete initialization, in case child & parent are instantiated at the 'same' time
# Required to avoid "Thread.__init__() not called" exceptions on the parent
time.sleep(0.1)
while self.parent_timer.is_alive():
self.logger.info(f"Timer '{self.timer_id}' is waiting for parent timer '{self.parent_timer.timer_id}' to finish")
time.sleep(0.2)
......
......@@ -471,9 +471,9 @@ class PlayCommand(EngineExecutor):
start_preload = entries[0].start_unix - self.config.get("preload_offset")
start_play = entries[0].start_unix
super().__init__("PLAY", None, start_preload, self.do_preload, entries)
EngineExecutor("PLAY", self, start_play, self.do_play, entries)
preload_timer = super().__init__("PLAY", None, start_preload, self.do_preload, entries)
self.on_ready(lambda: EngineExecutor("PLAY", self, start_play, self.do_play, entries))
def do_preload(self, entries):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment