diff --git a/plexpy/__init__.py b/plexpy/__init__.py index f50284a9..b975e4a6 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -1050,6 +1050,10 @@ def shutdown(restart=False, update=False, checkout=False): cherrypy.engine.exit() SCHED.shutdown(wait=False) + # Stop the notification threads + for i in range(CONFIG.NOTIFICATION_THREADS): + NOTIFY_QUEUE.put(None) + CONFIG.write() if not restart and not update and not checkout: diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index c0411e93..2e0c90b4 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -41,16 +41,21 @@ def process_queue(): queue = plexpy.NOTIFY_QUEUE while True: params = queue.get() - if params: + + if params is None: + break + elif params: if 'notifier_id' in params: notify(**params) else: add_notifier_each(**params) queue.task_done() + logger.info(u"PlexPy NotificationHandler :: Notification thread exiting...") + def start_threads(num_threads=1): - logger.info(u"PlexPy NotificationHandler :: Starting background notification handler.") + logger.info(u"PlexPy NotificationHandler :: Starting background notification handler ({} threads).".format(num_threads)) for x in range(num_threads): thread = threading.Thread(target=process_queue) thread.daemon = True