From 019f014dfe56154e8441d1d79213fa99791c1b8e Mon Sep 17 00:00:00 2001
From: David Trattnig <david.trattnig@o94.at>
Date: Mon, 14 Dec 2020 22:06:14 +0100
Subject: [PATCH] TImer ID as thread names. #62

---
 src/core/control.py         | 9 ++++++---
 src/scheduling/scheduler.py | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/core/control.py b/src/core/control.py
index e099aa18..9adac8cc 100644
--- a/src/core/control.py
+++ b/src/core/control.py
@@ -264,23 +264,27 @@ class EngineExecutor(Timer):
     def exec_now(self):
         """
         Immediate execution within a thread. It's not stored in the timer store.
+
+        Assigns the `timer_id` as the thread name.
         """
         self.direct_exec = True
         self.wait_for_parent()
-        thread = Thread(target = self.func, args = (self.param,))
+        thread = Thread(name=self.timer_id, target=self.func, args=(self.param,))
         thread.start()
-        self.cancel()
        
 
     def exec_timed(self):
         """
         Timed execution in a thread.
+
+        Assigns the `timer_id` as the thread name.
         """
         def wrapper_func(param=None):
             self.wait_for_parent()       
             if param: self.func(param,)
             else: self.func()
         super().__init__(self.diff, wrapper_func, (self.param,))
+        self._name = self.timer_id
 
 
     def update_store(self):
@@ -303,7 +307,6 @@ class EngineExecutor(Timer):
                 # Check if existing timer has been executed already -> don't update
                 if not existing_command.is_alive():
                     self.logger.debug(f"Existing dead timer with ID: {self.timer_id}. Don't update.")
-                    self.cancel()
                     return False
 
                 # Still waiting for execution -> update
diff --git a/src/scheduling/scheduler.py b/src/scheduling/scheduler.py
index 931e9184..5fb0d445 100644
--- a/src/scheduling/scheduler.py
+++ b/src/scheduling/scheduler.py
@@ -471,7 +471,7 @@ class PlayCommand(EngineExecutor):
 
         start_preload = entries[0].start_unix - self.config.get("preload_offset")
         start_play = entries[0].start_unix
-        super().__init__("PRELOAD", None, start_preload, self.do_preload, entries)
+        super().__init__("PLAY", None, start_preload, self.do_preload, entries)
         EngineExecutor("PLAY", self, start_play, self.do_play, entries)
 
 
-- 
GitLab