diff --git a/resources/lib/entrypoint/__init__.py b/resources/lib/entrypoint/__init__.py index 7bac52d8..3778b389 100644 --- a/resources/lib/entrypoint/__init__.py +++ b/resources/lib/entrypoint/__init__.py @@ -13,6 +13,7 @@ from emby import Emby ################################################################################################# Emby.set_loghandler(loghandler.LogHandler, logging.DEBUG) +loghandler.reset() loghandler.config() LOG = logging.getLogger('EMBY.entrypoint') diff --git a/resources/lib/entrypoint/service.py b/resources/lib/entrypoint/service.py index ba60f6ad..68c6d1d5 100644 --- a/resources/lib/entrypoint/service.py +++ b/resources/lib/entrypoint/service.py @@ -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()) diff --git a/resources/lib/helper/loghandler.py b/resources/lib/helper/loghandler.py index 4eb824d5..8fb2698f 100644 --- a/resources/lib/helper/loghandler.py +++ b/resources/lib/helper/loghandler.py @@ -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): diff --git a/service.py b/service.py index 19af8232..e88b2936 100644 --- a/service.py +++ b/service.py @@ -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: