Merge pull request #145 from yedpodtrzitko/yed/hold-the-jobs

dont run job threads needlessly
This commit is contained in:
Travis Abendshien
2024-05-08 10:36:58 -07:00
committed by GitHub

View File

@@ -133,19 +133,20 @@ class NavigationState:
class Consumer(QThread):
MARKER_QUIT = "MARKER_QUIT"
def __init__(self, queue) -> None:
self.queue = queue
QThread.__init__(self)
def run(self):
self.active = True
while self.active:
while True:
try:
job = self.queue.get(timeout=0.2)
# print('Running job...')
# logging.info(*job[1])
job = self.queue.get()
if job == self.MARKER_QUIT:
break
job[0](*job[1])
except (Empty, RuntimeError):
except RuntimeError:
pass
def set_page_count(self, count: int):
@@ -180,7 +181,7 @@ class QtDriver(QObject):
# self.title_text: str = self.base_title
# self.buffer = {}
self.thumb_job_queue: Queue = Queue()
self.thumb_threads = []
self.thumb_threads: list[Consumer] = []
self.thumb_cutoff: float = time.time()
# self.selected: list[tuple[int,int]] = [] # (Thumb Index, Page Index)
self.selected: list[tuple[ItemType, int]] = [] # (Item Type, Item ID)
@@ -553,10 +554,14 @@ class QtDriver(QObject):
self.settings.setValue("last_library", self.lib.library_dir)
self.settings.sync()
logging.info("[SHUTDOWN] Ending Thumbnail Threads...")
for _ in self.thumb_threads:
self.thumb_job_queue.put(Consumer.MARKER_QUIT)
# wait for threads to quit
for thread in self.thumb_threads:
thread.active = False
thread.quit()
thread.wait()
QApplication.quit()
def save_library(self, show_status=True):