Set signal.stopped = True on closing

This commit is contained in:
messense 2017-03-16 11:55:10 +08:00
parent 11a3cf9b99
commit e27812bf3e
No known key found for this signature in database
GPG Key ID: BB41A8A2C716CCA9
2 changed files with 6 additions and 3 deletions

View File

@ -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,

View File

@ -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
))