Fix service restart

This commit is contained in:
angelblue05 2019-01-09 15:46:22 -06:00
parent 79e335f185
commit 25dbfd3a0e
2 changed files with 34 additions and 14 deletions

View File

@ -128,6 +128,8 @@ class Service(xbmc.Monitor):
self.shutdown()
raise Exception("ExitService")
def start_default(self):
try:

View File

@ -4,6 +4,7 @@
import logging
import os
import threading
import sys
import xbmc
@ -40,6 +41,30 @@ DELAY = int(settings('startupDelay') or 0)
#################################################################################################
class ServiceManager(threading.Thread):
''' Service thread.
To allow to restart and reload modules internally.
'''
exception = None
def __init__(self):
threading.Thread.__init__(self)
def run(self):
service = Service()
try:
service.service()
except Exception as error:
if not 'ExitService' in error:
service.shutdown()
self.exception = error
if __name__ == "__main__":
LOG.warn("-->[ service ]")
@ -47,20 +72,15 @@ if __name__ == "__main__":
while True:
try:
session = Service()
try:
if DELAY and xbmc.Monitor().waitForAbort(DELAY):
raise Exception("Aborted during startup delay")
session.service()
except Exception as error: # TODO, build exceptions
session = ServiceManager()
session.start()
session.join() # Block until the thread exits.
LOG.exception(error)
session.shutdown()
if 'RestartService' in error:
if 'RestartService' in session.exception:
continue
except Exception as error:
@ -70,6 +90,4 @@ if __name__ == "__main__":
break
break
LOG.warn("--<[ service ]")