1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-28 12:30:00 +00:00

Revert daemon in favor of timeout

This commit is contained in:
blitzmann 2020-08-30 13:49:45 -04:00
parent b0a055a870
commit ef49e2b5b3

View File

@ -3,6 +3,7 @@ from __future__ import division, print_function, unicode_literals
import threading
import abc
import uuid
import time
try:
import queue
@ -59,7 +60,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,8 +102,18 @@ class WorkerThread(threading.Thread):
# Main thread loop starting the different tasks
def run(self):
# this blocks until something is available
item = self.queue.get()
main_thread = _get_main_thread()
while main_thread.is_alive():
try:
# this blocks until something is available. This can cause issues when the main thread dies - this
# thread will remain alive. We implement a timeout to unblock every second which allows us to check if
# the main thread is still alive.
# We don't use a daemon here because we don't want the tasks to just be abruptly halted, leading to
# possible file / database corruption
item = self.queue.get(timeout=1)
except queue.Empty as ex:
time.sleep(1)
continue
with self.doLock:
# add to list so that in-progress tasks show up