From 45eb2aac60dda0616e27ae77594ef02dad3917b3 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Mon, 8 Oct 2018 22:35:40 -0500 Subject: [PATCH] Ensure all threads are terminated correctly --- resources/lib/entrypoint/service.py | 1 + resources/lib/library.py | 37 +++++++++++++---------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index 7d2c3428..899c86a2 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -118,6 +118,7 @@ class Service(xbmc.Monitor): if self.waitForAbort(1): break + window('emby_should_stop.bool', True) self.shutdown() def start_default(self): diff --git a/resources/lib/library.py b/resources/lib/library.py index 615af880..a2d501d4 100644 --- a/resources/lib/library.py +++ b/resources/lib/library.py @@ -623,10 +623,6 @@ class UpdatedWorker(threading.Thread): try: item = self.queue.get(timeout=1) except Queue.Empty: - - LOG.info("--<[ q:updated/%s ]", id(self)) - self.is_done = True - break obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])[item['Type']] @@ -645,6 +641,9 @@ class UpdatedWorker(threading.Thread): if window('emby_should_stop.bool'): break + LOG.info("--<[ q:updated/%s ]", id(self)) + self.is_done = True + class UserDataWorker(threading.Thread): is_done = False @@ -668,10 +667,6 @@ class UserDataWorker(threading.Thread): try: item = self.queue.get(timeout=1) except Queue.Empty: - - LOG.info("--<[ q:userdata/%s ]", id(self)) - self.is_done = True - break obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])['UserData'] @@ -689,6 +684,9 @@ class UserDataWorker(threading.Thread): if window('emby_should_stop.bool'): break + LOG.info("--<[ q:userdata/%s ]", id(self)) + self.is_done = True + class SortWorker(threading.Thread): is_done = False @@ -710,11 +708,7 @@ class SortWorker(threading.Thread): try: item_id = self.queue.get(timeout=1) except Queue.Empty: - - self.is_done = True - LOG.info("--<[ q:sort/%s ]", id(self)) - - return + break try: media = database.get_media_by_id(item_id) @@ -733,6 +727,9 @@ class SortWorker(threading.Thread): if window('emby_should_stop.bool'): break + LOG.info("--<[ q:sort/%s ]", id(self)) + self.is_done = True + class RemovedWorker(threading.Thread): is_done = False @@ -756,10 +753,6 @@ class RemovedWorker(threading.Thread): try: item = self.queue.get(timeout=1) except Queue.Empty: - - LOG.info("--<[ q:removed/%s ]", id(self)) - self.is_done = True - break obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])['Remove'] @@ -777,6 +770,9 @@ class RemovedWorker(threading.Thread): if window('emby_should_stop.bool'): break + LOG.info("--<[ q:removed/%s ]", id(self)) + self.is_done = True + class NotifyWorker(threading.Thread): is_done = False @@ -796,10 +792,6 @@ class NotifyWorker(threading.Thread): try: item = self.queue.get(timeout=3) except Queue.Empty: - - LOG.info("--<[ q:notify/%s ]", id(self)) - self.is_done = True - break time = self.music_time if item[0] == 'Audio' else self.video_time @@ -812,3 +804,6 @@ class NotifyWorker(threading.Thread): if window('emby_should_stop.bool'): break + + LOG.info("--<[ q:notify/%s ]", id(self)) + self.is_done = True