From 6a61fce84e5f14a56ef6c26e72523ab81d4504b4 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Mon, 15 Jan 2018 11:53:15 -0800 Subject: [PATCH] worker process should ignore SIGINT when run_multiple --- sanic/server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sanic/server.py b/sanic/server.py index 2c549be2..5855224b 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -5,7 +5,7 @@ from functools import partial from inspect import isawaitable from multiprocessing import Process from signal import ( - SIGTERM, SIGINT, + SIGTERM, SIGINT, SIG_IGN, signal as signal_func, Signals ) @@ -607,6 +607,10 @@ def serve(host, port, request_handler, error_handler, before_start=None, trigger_events(after_start, loop) + # Ignore SIGINT when run_multiple + if run_multiple: + signal_func(SIGINT, SIG_IGN) + # Register signals for graceful termination if register_sys_signals: _singals = (SIGTERM,) if run_multiple else (SIGINT, SIGTERM) @@ -694,6 +698,7 @@ def serve_multiple(server_settings, workers): signal_func(SIGTERM, lambda s, f: sig_handler(s, f)) processes = [] + for _ in range(workers): process = Process(target=serve, kwargs=server_settings) process.daemon = True