diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 4e25479d..508c92a0 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -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) diff --git a/plexpy/logger.py b/plexpy/logger.py index e8537ad3..1438f32e 100644 --- a/plexpy/logger.py +++ b/plexpy/logger.py @@ -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 diff --git a/plexpy/web_socket.py b/plexpy/web_socket.py index 0ab81120..487ce045 100644 --- a/plexpy/web_socket.py +++ b/plexpy/web_socket.py @@ -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: