Browse Source

fix: wrap old handler

master
lanvent 1 year ago
parent
commit
8193ecf5f6
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      app.py

+ 9
- 5
app.py View File

@@ -8,18 +8,22 @@ from plugins import *
import signal import signal
import sys 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(): def run():
try: try:
# load config # load config
load_config() load_config()
# ctrl + c # ctrl + c
signal.signal(signal.SIGINT, sigterm_handler)
sigterm_handler_wrap(signal.SIGINT)
# kill signal # kill signal
signal.signal(signal.SIGTERM, sigterm_handler)
sigterm_handler_wrap(signal.SIGTERM)


# create channel # create channel
channel_name=conf().get('channel_type', 'wx') channel_name=conf().get('channel_type', 'wx')


Loading…
Cancel
Save