Revert "Revert "Try shutting down PKC more cleanly""

This reverts commit a1f1e332b3.
This commit is contained in:
tomkat83 2017-05-17 10:09:57 +02:00
parent a63b90dd5f
commit bce800abc2
2 changed files with 15 additions and 5 deletions

View file

@ -14,6 +14,7 @@ from PlexFunctions import scrobble
from kodidb_functions import get_kodiid_from_filename from kodidb_functions import get_kodiid_from_filename
from PlexAPI import API from PlexAPI import API
from variables import REMAP_TYPE_FROM_PLEXTYPE from variables import REMAP_TYPE_FROM_PLEXTYPE
import state
############################################################################### ###############################################################################
@ -137,6 +138,10 @@ class KodiMonitor(Monitor):
sleep(5000) sleep(5000)
window('plex_runLibScan', value="full") window('plex_runLibScan', value="full")
elif method == "System.OnQuit":
log.info('Kodi OnQuit detected - shutting down')
state.STOP_PKC = True
def PlayBackStart(self, data): def PlayBackStart(self, data):
""" """
Called whenever a playback is started Called whenever a playback is started

View file

@ -133,9 +133,16 @@ class Service():
logLevel = 0 logLevel = 0
return logLevel return logLevel
def __stop_PKC(self):
"""
Kodi's abortRequested is really unreliable :-(
"""
return self.monitor.abortRequested() or state.STOP_PKC
def ServiceEntryPoint(self): def ServiceEntryPoint(self):
# Important: Threads depending on abortRequest will not trigger # Important: Threads depending on abortRequest will not trigger
# if profile switch happens more than once. # if profile switch happens more than once.
__stop_PKC = self.__stop_PKC
monitor = self.monitor monitor = self.monitor
kodiProfile = v.KODI_PROFILE kodiProfile = v.KODI_PROFILE
@ -161,7 +168,7 @@ class Service():
welcome_msg = True welcome_msg = True
counter = 0 counter = 0
while not monitor.abortRequested(): while not __stop_PKC():
if tryEncode(window('plex_kodiProfile')) != kodiProfile: if tryEncode(window('plex_kodiProfile')) != kodiProfile:
# Profile change happened, terminate this thread and others # Profile change happened, terminate this thread and others
@ -241,14 +248,13 @@ class Service():
# Server went offline # Server went offline
break break
if monitor.waitForAbort(5): if monitor.waitForAbort(3):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
break break
sleep(50)
else: else:
# Wait until Plex server is online # Wait until Plex server is online
# or Kodi is shut down. # or Kodi is shut down.
while not monitor.abortRequested(): while not self.__stop_PKC():
server = self.user.getServer() server = self.user.getServer()
if server is False: if server is False:
# No server info set in add-on settings # No server info set in add-on settings
@ -316,7 +322,6 @@ class Service():
if monitor.waitForAbort(0.05): if monitor.waitForAbort(0.05):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
break break
# Terminating PlexKodiConnect # Terminating PlexKodiConnect
# Tell all threads to terminate (e.g. several lib sync threads) # Tell all threads to terminate (e.g. several lib sync threads)