Ensure all threads are terminated correctly

This commit is contained in:
angelblue05 2018-10-08 22:35:40 -05:00
parent 1147a3b2bf
commit 45eb2aac60
2 changed files with 17 additions and 21 deletions

View file

@ -118,6 +118,7 @@ class Service(xbmc.Monitor):
if self.waitForAbort(1): if self.waitForAbort(1):
break break
window('emby_should_stop.bool', True)
self.shutdown() self.shutdown()
def start_default(self): def start_default(self):

View file

@ -623,10 +623,6 @@ class UpdatedWorker(threading.Thread):
try: try:
item = self.queue.get(timeout=1) item = self.queue.get(timeout=1)
except Queue.Empty: except Queue.Empty:
LOG.info("--<[ q:updated/%s ]", id(self))
self.is_done = True
break break
obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])[item['Type']] 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'): if window('emby_should_stop.bool'):
break break
LOG.info("--<[ q:updated/%s ]", id(self))
self.is_done = True
class UserDataWorker(threading.Thread): class UserDataWorker(threading.Thread):
is_done = False is_done = False
@ -668,10 +667,6 @@ class UserDataWorker(threading.Thread):
try: try:
item = self.queue.get(timeout=1) item = self.queue.get(timeout=1)
except Queue.Empty: except Queue.Empty:
LOG.info("--<[ q:userdata/%s ]", id(self))
self.is_done = True
break break
obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])['UserData'] 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'): if window('emby_should_stop.bool'):
break break
LOG.info("--<[ q:userdata/%s ]", id(self))
self.is_done = True
class SortWorker(threading.Thread): class SortWorker(threading.Thread):
is_done = False is_done = False
@ -710,11 +708,7 @@ class SortWorker(threading.Thread):
try: try:
item_id = self.queue.get(timeout=1) item_id = self.queue.get(timeout=1)
except Queue.Empty: except Queue.Empty:
break
self.is_done = True
LOG.info("--<[ q:sort/%s ]", id(self))
return
try: try:
media = database.get_media_by_id(item_id) media = database.get_media_by_id(item_id)
@ -733,6 +727,9 @@ class SortWorker(threading.Thread):
if window('emby_should_stop.bool'): if window('emby_should_stop.bool'):
break break
LOG.info("--<[ q:sort/%s ]", id(self))
self.is_done = True
class RemovedWorker(threading.Thread): class RemovedWorker(threading.Thread):
is_done = False is_done = False
@ -756,10 +753,6 @@ class RemovedWorker(threading.Thread):
try: try:
item = self.queue.get(timeout=1) item = self.queue.get(timeout=1)
except Queue.Empty: except Queue.Empty:
LOG.info("--<[ q:removed/%s ]", id(self))
self.is_done = True
break break
obj = MEDIA[item['Type']](self.args[0], embydb, kodidb, self.args[1])['Remove'] 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'): if window('emby_should_stop.bool'):
break break
LOG.info("--<[ q:removed/%s ]", id(self))
self.is_done = True
class NotifyWorker(threading.Thread): class NotifyWorker(threading.Thread):
is_done = False is_done = False
@ -796,10 +792,6 @@ class NotifyWorker(threading.Thread):
try: try:
item = self.queue.get(timeout=3) item = self.queue.get(timeout=3)
except Queue.Empty: except Queue.Empty:
LOG.info("--<[ q:notify/%s ]", id(self))
self.is_done = True
break break
time = self.music_time if item[0] == 'Audio' else self.video_time 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'): if window('emby_should_stop.bool'):
break break
LOG.info("--<[ q:notify/%s ]", id(self))
self.is_done = True