Set signal.stopped = True
on closing
This commit is contained in:
parent
11a3cf9b99
commit
e27812bf3e
|
@ -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,
|
after_start=None, before_stop=None, after_stop=None, debug=False,
|
||||||
request_timeout=60, ssl=None, sock=None, request_max_size=None,
|
request_timeout=60, ssl=None, sock=None, request_max_size=None,
|
||||||
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
|
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.
|
"""Start asynchronous HTTP Server on an individual process.
|
||||||
|
|
||||||
:param host: Address to host on
|
: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)
|
trigger_events(before_start, loop)
|
||||||
|
|
||||||
connections = connections if connections is not None else set()
|
connections = connections if connections is not None else set()
|
||||||
signal = Signal()
|
|
||||||
server = partial(
|
server = partial(
|
||||||
protocol,
|
protocol,
|
||||||
loop=loop,
|
loop=loop,
|
||||||
|
|
|
@ -11,7 +11,7 @@ except ImportError:
|
||||||
import uvloop
|
import uvloop
|
||||||
import gunicorn.workers.base as base
|
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
|
from sanic.websocket import WebSocketProtocol
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class GunicornWorker(base.Worker):
|
||||||
self.servers = []
|
self.servers = []
|
||||||
self.connections = set()
|
self.connections = set()
|
||||||
self.exit_code = 0
|
self.exit_code = 0
|
||||||
|
self.signal = Signal()
|
||||||
|
|
||||||
def init_process(self):
|
def init_process(self):
|
||||||
# create new event_loop after fork
|
# create new event_loop after fork
|
||||||
|
@ -67,6 +68,7 @@ class GunicornWorker(base.Worker):
|
||||||
self.servers.clear()
|
self.servers.clear()
|
||||||
|
|
||||||
# prepare connections for closing
|
# prepare connections for closing
|
||||||
|
self.signal.stopped = True
|
||||||
for conn in self.connections:
|
for conn in self.connections:
|
||||||
conn.close_if_idle()
|
conn.close_if_idle()
|
||||||
|
|
||||||
|
@ -91,6 +93,7 @@ class GunicornWorker(base.Worker):
|
||||||
self.servers.append(await serve(
|
self.servers.append(await serve(
|
||||||
sock=sock,
|
sock=sock,
|
||||||
connections=self.connections,
|
connections=self.connections,
|
||||||
|
signal=self.signal,
|
||||||
**self._server_settings
|
**self._server_settings
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user