From bce800abc2b37350a6f64dcf78f742539cb03aea Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Wed, 17 May 2017 10:09:57 +0200 Subject: [PATCH] Revert "Revert "Try shutting down PKC more cleanly"" This reverts commit a1f1e332b321a9a251c107e3e427338ff9312999. --- resources/lib/kodimonitor.py | 5 +++++ service.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 4e19721e..579c9033 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -14,6 +14,7 @@ from PlexFunctions import scrobble from kodidb_functions import get_kodiid_from_filename from PlexAPI import API from variables import REMAP_TYPE_FROM_PLEXTYPE +import state ############################################################################### @@ -137,6 +138,10 @@ class KodiMonitor(Monitor): sleep(5000) window('plex_runLibScan', value="full") + elif method == "System.OnQuit": + log.info('Kodi OnQuit detected - shutting down') + state.STOP_PKC = True + def PlayBackStart(self, data): """ Called whenever a playback is started diff --git a/service.py b/service.py index ef174ce2..08119cb5 100644 --- a/service.py +++ b/service.py @@ -133,9 +133,16 @@ class Service(): logLevel = 0 return logLevel + def __stop_PKC(self): + """ + Kodi's abortRequested is really unreliable :-( + """ + return self.monitor.abortRequested() or state.STOP_PKC + def ServiceEntryPoint(self): # Important: Threads depending on abortRequest will not trigger # if profile switch happens more than once. + __stop_PKC = self.__stop_PKC monitor = self.monitor kodiProfile = v.KODI_PROFILE @@ -161,7 +168,7 @@ class Service(): welcome_msg = True counter = 0 - while not monitor.abortRequested(): + while not __stop_PKC(): if tryEncode(window('plex_kodiProfile')) != kodiProfile: # Profile change happened, terminate this thread and others @@ -241,14 +248,13 @@ class Service(): # Server went offline break - if monitor.waitForAbort(5): + if monitor.waitForAbort(3): # Abort was requested while waiting. We should exit break - sleep(50) else: # Wait until Plex server is online # or Kodi is shut down. - while not monitor.abortRequested(): + while not self.__stop_PKC(): server = self.user.getServer() if server is False: # No server info set in add-on settings @@ -316,7 +322,6 @@ class Service(): if monitor.waitForAbort(0.05): # Abort was requested while waiting. We should exit break - # Terminating PlexKodiConnect # Tell all threads to terminate (e.g. several lib sync threads)