From e27812bf3e843e001ea449d4ec588baf9d4d3d3c Mon Sep 17 00:00:00 2001 From: messense Date: Thu, 16 Mar 2017 11:55:10 +0800 Subject: [PATCH] Set `signal.stopped = True` on closing --- sanic/server.py | 4 ++-- sanic/worker.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index f044517e..00bb2331 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -313,7 +313,8 @@ def serve(host, port, request_handler, error_handler, before_start=None, after_start=None, before_stop=None, after_stop=None, debug=False, request_timeout=60, ssl=None, sock=None, request_max_size=None, reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100, - register_sys_signals=True, run_async=False, connections=None): + register_sys_signals=True, run_async=False, connections=None, + signal=Signal()): """Start asynchronous HTTP Server on an individual process. :param host: Address to host on @@ -350,7 +351,6 @@ def serve(host, port, request_handler, error_handler, before_start=None, trigger_events(before_start, loop) connections = connections if connections is not None else set() - signal = Signal() server = partial( protocol, loop=loop, diff --git a/sanic/worker.py b/sanic/worker.py index 10b7e19b..2ed2672e 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -11,7 +11,7 @@ except ImportError: import uvloop import gunicorn.workers.base as base -from sanic.server import trigger_events, serve, HttpProtocol +from sanic.server import trigger_events, serve, HttpProtocol, Signal from sanic.websocket import WebSocketProtocol @@ -27,6 +27,7 @@ class GunicornWorker(base.Worker): self.servers = [] self.connections = set() self.exit_code = 0 + self.signal = Signal() def init_process(self): # create new event_loop after fork @@ -67,6 +68,7 @@ class GunicornWorker(base.Worker): self.servers.clear() # prepare connections for closing + self.signal.stopped = True for conn in self.connections: conn.close_if_idle() @@ -91,6 +93,7 @@ class GunicornWorker(base.Worker): self.servers.append(await serve( sock=sock, connections=self.connections, + signal=self.signal, **self._server_settings ))