From 9b9e29a3b6f6b71b5ed546d87fafa53911f5764c Mon Sep 17 00:00:00 2001
From: blitzmann <holmes.ryan.90@gmail.com>
Date: Sun, 30 Aug 2020 13:29:42 -0400
Subject: [PATCH] Implement worker thread as a daemon

---
 cps/services/worker.py | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/cps/services/worker.py b/cps/services/worker.py
index 14c94df6..92c5fa3d 100644
--- a/cps/services/worker.py
+++ b/cps/services/worker.py
@@ -59,7 +59,7 @@ class WorkerThread(threading.Thread):
         threading.Thread.__init__(self)
 
         self.dequeued = list()
-
+        self.daemon = True
         self.doLock = threading.Lock()
         self.queue = ImprovedQueue()
         self.num = 0
@@ -101,24 +101,23 @@ class WorkerThread(threading.Thread):
 
     # Main thread loop starting the different tasks
     def run(self):
-        main_thread = _get_main_thread()
-        while main_thread.is_alive():
-            # this blocks until something is available
-            item = self.queue.get()
-            with self.doLock:
-                # add to list so that in-progress tasks show up
-                self.dequeued.append(item)
-
-            # once we hit our trigger, start cleaning up dead tasks
-            if len(self.dequeued) > TASK_CLEANUP_TRIGGER:
-                self.cleanup_tasks()
-
-            # sometimes tasks (like Upload) don't actually have work to do and are created as already finished
-            if item.task.stat is STAT_WAITING:
-                # CalibreTask.start() should wrap all exceptions in it's own error handling
-                item.task.start(self)
-
-            self.queue.task_done()
+        # this blocks until something is available
+        item = self.queue.get()
+
+        with self.doLock:
+            # add to list so that in-progress tasks show up
+            self.dequeued.append(item)
+
+        # once we hit our trigger, start cleaning up dead tasks
+        if len(self.dequeued) > TASK_CLEANUP_TRIGGER:
+            self.cleanup_tasks()
+
+        # sometimes tasks (like Upload) don't actually have work to do and are created as already finished
+        if item.task.stat is STAT_WAITING:
+            # CalibreTask.start() should wrap all exceptions in it's own error handling
+            item.task.start(self)
+
+        self.queue.task_done()
 
 
 class CalibreTask:
-- 
2.18.1