1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-26 01:50:31 +00:00

Implement worker thread as a daemon

This commit is contained in:
blitzmann 2020-08-30 13:29:42 -04:00
parent e7eb5b6ea6
commit 9b9e29a3b6

View File

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