mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-25 20:30:28 +08:00
支持信号重新加载配置
This commit is contained in:
parent
48154b2be9
commit
baa64f3dc5
43
main.py
43
main.py
@ -39,6 +39,7 @@ ROUTES = [
|
|||||||
|
|
||||||
server: Optional[tornado.httpserver.HTTPServer] = None
|
server: Optional[tornado.httpserver.HTTPServer] = None
|
||||||
|
|
||||||
|
cmd_args = None
|
||||||
shut_down_event: Optional[asyncio.Event] = None
|
shut_down_event: Optional[asyncio.Event] = None
|
||||||
|
|
||||||
|
|
||||||
@ -55,11 +56,12 @@ async def main():
|
|||||||
def init():
|
def init():
|
||||||
init_signal_handlers()
|
init_signal_handlers()
|
||||||
|
|
||||||
args = parse_args()
|
global cmd_args
|
||||||
|
cmd_args = parse_args()
|
||||||
|
|
||||||
init_logging(args.debug)
|
init_logging(cmd_args.debug)
|
||||||
logger.info('App started, initializing')
|
logger.info('App started, initializing')
|
||||||
config.init(args)
|
config.init(cmd_args)
|
||||||
|
|
||||||
utils.request.init()
|
utils.request.init()
|
||||||
models.database.init()
|
models.database.init()
|
||||||
@ -83,21 +85,36 @@ def init_signal_handlers():
|
|||||||
global shut_down_event
|
global shut_down_event
|
||||||
shut_down_event = asyncio.Event()
|
shut_down_event = asyncio.Event()
|
||||||
|
|
||||||
signums = (signal.SIGINT, signal.SIGTERM)
|
is_win = sys.platform == 'win32'
|
||||||
try:
|
loop = asyncio.get_running_loop()
|
||||||
loop = asyncio.get_running_loop()
|
if not is_win:
|
||||||
for signum in signums:
|
def add_signal_handler(signum, callback):
|
||||||
loop.add_signal_handler(signum, on_shut_down_signal)
|
loop.add_signal_handler(signum, callback)
|
||||||
except NotImplementedError:
|
else:
|
||||||
# 不太安全,但Windows只能用这个
|
def add_signal_handler(signum, callback):
|
||||||
for signum in signums:
|
# 不太安全,但Windows只能用这个
|
||||||
signal.signal(signum, on_shut_down_signal)
|
signal.signal(signum, lambda _signum, _frame: loop.call_soon(callback))
|
||||||
|
|
||||||
|
shut_down_signums = (signal.SIGINT, signal.SIGTERM)
|
||||||
|
if not is_win:
|
||||||
|
reload_signum = signal.SIGHUP
|
||||||
|
else:
|
||||||
|
reload_signum = signal.SIGBREAK
|
||||||
|
|
||||||
|
for shut_down_signum in shut_down_signums:
|
||||||
|
add_signal_handler(shut_down_signum, on_shut_down_signal)
|
||||||
|
add_signal_handler(reload_signum, on_reload_signal)
|
||||||
|
|
||||||
|
|
||||||
def on_shut_down_signal(*_args):
|
def on_shut_down_signal():
|
||||||
shut_down_event.set()
|
shut_down_event.set()
|
||||||
|
|
||||||
|
|
||||||
|
def on_reload_signal():
|
||||||
|
logger.info('Received reload signal')
|
||||||
|
config.reload(cmd_args)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(description='用于OBS的仿YouTube风格的bilibili直播评论栏')
|
parser = argparse.ArgumentParser(description='用于OBS的仿YouTube风格的bilibili直播评论栏')
|
||||||
parser.add_argument('--host', help='服务器host,默认和配置中的一样', default=None)
|
parser.add_argument('--host', help='服务器host,默认和配置中的一样', default=None)
|
||||||
|
Loading…
Reference in New Issue
Block a user