From 8193ecf5f6aa6e5586f00474c064d92d741c9d55 Mon Sep 17 00:00:00 2001 From: lanvent Date: Thu, 6 Apr 2023 11:27:50 +0800 Subject: [PATCH] fix: wrap old handler --- app.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 4e51ab9..a6f9f5f 100644 --- a/app.py +++ b/app.py @@ -8,18 +8,22 @@ from plugins import * import signal import sys -def sigterm_handler(_signo, _stack_frame): - conf().save_user_datas() - sys.exit(0) +def sigterm_handler_wrap(_signo): + old_handler = signal.getsignal(_signo) + def func(_signo, _stack_frame): + logger.info("signal {} received, exiting...".format(_signo)) + conf().save_user_datas() + return old_handler(_signo, _stack_frame) + signal.signal(_signo, func) def run(): try: # load config load_config() # ctrl + c - signal.signal(signal.SIGINT, sigterm_handler) + sigterm_handler_wrap(signal.SIGINT) # kill signal - signal.signal(signal.SIGTERM, sigterm_handler) + sigterm_handler_wrap(signal.SIGTERM) # create channel channel_name=conf().get('channel_type', 'wx')