Try to cleanly shutdown loggers

This commit is contained in:
JonnyWong16 2018-01-20 11:27:58 -08:00
parent 79609c384e
commit 0fad245148
3 changed files with 22 additions and 5 deletions

View file

@ -1587,6 +1587,7 @@ def upgrade():
def shutdown(restart=False, update=False, checkout=False):
cherrypy.engine.exit()
SCHED.shutdown(wait=False)
activity_handler.ACTIVITY_SCHED.shutdown(wait=False)
# Stop the notification threads
for i in range(CONFIG.NOTIFICATION_THREADS):
@ -1617,23 +1618,35 @@ def shutdown(restart=False, update=False, checkout=False):
if restart:
logger.info(u"Tautulli is restarting...")
exe = sys.executable
args = [exe, FULL_PATH]
args += ARGS
if '--nolaunch' not in args:
args += ['--nolaunch']
# os.execv fails with spaced names on Windows
# https://bugs.python.org/issue19066
# Separate out logger so we can shutdown logger after
if NOFORK:
logger.info('Running as service, not forking. Exiting...')
elif os.name == 'nt':
logger.info('Restarting Tautulli with %s', args)
subprocess.Popen(args, cwd=os.getcwd())
else:
logger.info('Restarting Tautulli with %s', args)
logger.shutdown()
# os.execv fails with spaced names on Windows
# https://bugs.python.org/issue19066
if NOFORK:
pass
elif os.name == 'nt':
subprocess.Popen(args, cwd=os.getcwd())
else:
os.execv(exe, args)
else:
logger.shutdown()
os._exit(0)

View file

@ -306,6 +306,11 @@ def initHooks(global_exceptions=True, thread_exceptions=True, pass_original=True
# Monkey patch the run() by monkey patching the __init__ method
threading.Thread.__init__ = new_init
def shutdown():
logging.shutdown()
# Expose logger methods
# Main Tautulli logger
info = logger.info

View file

@ -176,6 +176,7 @@ def process(opcode, data):
return False
try:
logger.websocket_debug(data)
info = json.loads(data)
except Exception as e:
logger.warn(u"Tautulli WebSocket :: Error decoding message from websocket: %s" % e)
@ -189,7 +190,6 @@ def process(opcode, data):
return False
if type == 'playing':
logger.websocket_debug(data)
time_line = info.get('PlaySessionStateNotification', info.get('_children', {}))
if not time_line:
@ -203,7 +203,6 @@ def process(opcode, data):
logger.error(u"Tautulli WebSocket :: Failed to process session data: %s." % e)
if type == 'timeline':
logger.websocket_debug(data)
time_line = info.get('TimelineEntry', info.get('_children', {}))
if not time_line: