Fix service restart

This commit is contained in:
angelblue05 2019-01-13 04:21:35 -06:00
parent 5db5372db5
commit 25ed1cb011
4 changed files with 47 additions and 13 deletions

View file

@ -13,6 +13,7 @@ from emby import Emby
#################################################################################################
Emby.set_loghandler(loghandler.LogHandler, logging.DEBUG)
loghandler.reset()
loghandler.config()
LOG = logging.getLogger('EMBY.entrypoint')

View file

@ -123,7 +123,6 @@ class Service(xbmc.Monitor):
window('emby.restart', clear=True)
dialog("notification", heading="{emby}", message=_(33193), icon="{emby}", time=1000, sound=False)
reload(objects)
raise Exception('RestartService')
@ -215,7 +214,7 @@ class Service(xbmc.Monitor):
except Exception as error:
LOG.exception(error)
return True
raise Exception("RestartService")
def onNotification(self, sender, method, data):
@ -422,11 +421,14 @@ class Service(xbmc.Monitor):
elif method == 'CheckUpdate':
if not self.check_update(True):
try:
self.check_update(True)
dialog("notification", heading="{emby}", message=_(21341), icon="{emby}", sound=False)
else:
dialog("notification", heading="{emby}", message=_(33181), icon="{emby}", sound=False)
window('emby.restart.bool', True)
except Exception as error:
if 'RestartService' in error:
dialog("notification", heading="{emby}", message=_(33181), icon="{emby}", sound=False)
window('emby.restart.bool', True)
def onSettingsChanged(self):
@ -499,6 +501,8 @@ class Service(xbmc.Monitor):
self.library_thread.stop_client()
if self.monitor is not None:
self.monitor.listener.stop()
self.monitor.webservice.stop()
LOG.warn("---<<<[ %s ]", client.get_addon_name())

View file

@ -18,6 +18,11 @@ def config():
logger.addHandler(LogHandler())
logger.setLevel(logging.DEBUG)
def reset():
for handler in logging.getLogger('EMBY').handlers:
logging.getLogger('EMBY').removeHandler(handler)
class LogHandler(logging.StreamHandler):

View file

@ -52,14 +52,18 @@ class ServiceManager(threading.Thread):
threading.Thread.__init__(self)
def run(self):
service = Service()
service = None
try:
service = Service()
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
raise Exception("Aborted during startup delay")
service.service()
except Exception as error:
if not 'ExitService' in error:
if not 'ExitService' in error and service is not None:
service.shutdown()
self.exception = error
@ -73,16 +77,36 @@ if __name__ == "__main__":
while True:
try:
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
raise Exception("Aborted during startup delay")
session = ServiceManager()
session.start()
session.join() # Block until the thread exits.
if 'RestartService' in session.exception:
''' Reload objects which depends on the patch module.
'''
LOG.warn("--[ RESTART ]")
import objects
import library
import full_sync
import monitor
reload_modules = ['objects.movies', 'objects.musicvideos', 'objects.tvshows',
'objects.music', 'objects.obj', 'objects.actions', 'objects.kodi.kodi',
'objects.kodi.movies', 'objects.kodi.musicvideos', 'objects.kodi.tvshows',
'objects.kodi.music', 'objects.kodi.artwork', 'objects.kodi.queries',
'objects.kodi.queries_music', 'objects.kodi.queries_texture']
for mod in reload_modules:
del sys.modules[mod]
reload(objects.kodi)
reload(objects)
reload(library)
reload(full_sync)
reload(monitor)
continue
except Exception as error: