dont run job threads needlessly

This commit is contained in:
yedpodtrzitko
2024-05-08 11:10:43 +08:00
parent 57a15f651e
commit 0e621011fc

View File

@@ -132,19 +132,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):
@@ -179,7 +180,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)
@@ -545,10 +546,9 @@ class QtDriver(QObject):
self.settings.setValue("last_library", self.lib.library_dir)
self.settings.sync()
logging.info("[SHUTDOWN] Ending Thumbnail Threads...")
for thread in self.thumb_threads:
thread.active = False
thread.quit()
thread.wait()
for _ in self.thumb_threads:
self.thumb_job_queue.put(Consumer.MARKER_QUIT)
QApplication.quit()
def save_library(self, show_status=True):