From e318253f311b417edc6d54fcaf54f2630f6b682b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 4 Aug 2022 23:48:36 +0200 Subject: [PATCH] Disable SIGCHLD Handler for now - keeping SIGTERM for DB writes --- changedetection.py | 6 ++++-- changedetectionio/changedetection.py | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/changedetection.py b/changedetection.py index f6e45040..8455315a 100755 --- a/changedetection.py +++ b/changedetection.py @@ -10,7 +10,7 @@ import multiprocessing import signal import os -def sigterm_handler(_signo, _stack_frame): +def sigchld_handler(_signo, _stack_frame): import sys print('Shutdown: Got SIGCHLD') # https://stackoverflow.com/questions/40453496/python-multiprocessing-capturing-signals-to-restart-child-processes-or-shut-do @@ -23,7 +23,9 @@ def sigterm_handler(_signo, _stack_frame): raise SystemExit if __name__ == '__main__': - signal.signal(signal.SIGCHLD, sigterm_handler) + + #signal.signal(signal.SIGCHLD, sigchld_handler) + # The only way I could find to get Flask to shutdown, is to wrap it and then rely on the subsystem issuing SIGTERM/SIGKILL parse_process = multiprocessing.Process(target=changedetection.main) parse_process.daemon = True diff --git a/changedetectionio/changedetection.py b/changedetectionio/changedetection.py index 6d07dfc8..34efd850 100755 --- a/changedetectionio/changedetection.py +++ b/changedetectionio/changedetection.py @@ -19,11 +19,10 @@ app = None def sigterm_handler(_signo, _stack_frame): global app global datastore - - app.config.exit.set() - datastore.sync_to_json() +# app.config.exit.set() print('Shutdown: Got SIGTERM, DB saved to disk') - raise SystemExit + datastore.sync_to_json() +# raise SystemExit def main(): global datastore @@ -91,6 +90,7 @@ def main(): datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], version_tag=__version__) app = changedetection_app(app_config, datastore) + signal.signal(signal.SIGTERM, sigterm_handler) # Go into cleanup mode