remove stop_event
This commit is contained in:
parent
df9884de3c
commit
1ddb01ac44
28
sanic/app.py
28
sanic/app.py
|
@ -554,19 +554,24 @@ class Sanic:
|
||||||
if protocol is None:
|
if protocol is None:
|
||||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||||
else HttpProtocol)
|
else HttpProtocol)
|
||||||
|
if stop_event is not None:
|
||||||
|
if debug:
|
||||||
|
warnings.simplefilter('default')
|
||||||
|
warnings.warn("stop_event will be removed from future versions.",
|
||||||
|
DeprecationWarning)
|
||||||
server_settings = self._helper(
|
server_settings = self._helper(
|
||||||
host=host, port=port, debug=debug, before_start=before_start,
|
host=host, port=port, debug=debug, before_start=before_start,
|
||||||
after_start=after_start, before_stop=before_stop,
|
after_start=after_start, before_stop=before_stop,
|
||||||
after_stop=after_stop, ssl=ssl, sock=sock, workers=workers,
|
after_stop=after_stop, ssl=ssl, sock=sock, workers=workers,
|
||||||
loop=loop, protocol=protocol, backlog=backlog,
|
loop=loop, protocol=protocol, backlog=backlog,
|
||||||
stop_event=stop_event, register_sys_signals=register_sys_signals)
|
register_sys_signals=register_sys_signals)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.is_running = True
|
self.is_running = True
|
||||||
if workers == 1:
|
if workers == 1:
|
||||||
serve(**server_settings)
|
serve(**server_settings)
|
||||||
else:
|
else:
|
||||||
serve_multiple(server_settings, workers, stop_event)
|
serve_multiple(server_settings, workers)
|
||||||
except:
|
except:
|
||||||
log.exception(
|
log.exception(
|
||||||
'Experienced exception while trying to serve')
|
'Experienced exception while trying to serve')
|
||||||
|
@ -592,16 +597,23 @@ class Sanic:
|
||||||
NOTE: This does not support multiprocessing and is not the preferred
|
NOTE: This does not support multiprocessing and is not the preferred
|
||||||
way to run a Sanic application.
|
way to run a Sanic application.
|
||||||
"""
|
"""
|
||||||
|
<<<<<<< df9884de3c7ca6ad248162c8f404afd0ed774359
|
||||||
if protocol is None:
|
if protocol is None:
|
||||||
protocol = (WebSocketProtocol if self.websocket_enabled
|
protocol = (WebSocketProtocol if self.websocket_enabled
|
||||||
else HttpProtocol)
|
else HttpProtocol)
|
||||||
|
=======
|
||||||
|
if stop_event is not None:
|
||||||
|
if debug:
|
||||||
|
warnings.simplefilter('default')
|
||||||
|
warnings.warn("stop_event will be removed from future versions.",
|
||||||
|
DeprecationWarning)
|
||||||
|
>>>>>>> remove stop_event
|
||||||
server_settings = self._helper(
|
server_settings = self._helper(
|
||||||
host=host, port=port, debug=debug, before_start=before_start,
|
host=host, port=port, debug=debug, before_start=before_start,
|
||||||
after_start=after_start, before_stop=before_stop,
|
after_start=after_start, before_stop=before_stop,
|
||||||
after_stop=after_stop, ssl=ssl, sock=sock,
|
after_stop=after_stop, ssl=ssl, sock=sock,
|
||||||
loop=loop or get_event_loop(), protocol=protocol,
|
loop=loop or get_event_loop(), protocol=protocol,
|
||||||
backlog=backlog, stop_event=stop_event,
|
backlog=backlog, run_async=True)
|
||||||
run_async=True)
|
|
||||||
|
|
||||||
return await serve(**server_settings)
|
return await serve(**server_settings)
|
||||||
|
|
||||||
|
@ -611,6 +623,7 @@ class Sanic:
|
||||||
protocol=HttpProtocol, backlog=100, stop_event=None,
|
protocol=HttpProtocol, backlog=100, stop_event=None,
|
||||||
register_sys_signals=True, run_async=False):
|
register_sys_signals=True, run_async=False):
|
||||||
"""Helper function used by `run` and `create_server`."""
|
"""Helper function used by `run` and `create_server`."""
|
||||||
|
<<<<<<< df9884de3c7ca6ad248162c8f404afd0ed774359
|
||||||
|
|
||||||
if isinstance(ssl, dict):
|
if isinstance(ssl, dict):
|
||||||
# try common aliaseses
|
# try common aliaseses
|
||||||
|
@ -622,6 +635,13 @@ class Sanic:
|
||||||
context.load_cert_chain(cert, keyfile=key)
|
context.load_cert_chain(cert, keyfile=key)
|
||||||
ssl = context
|
ssl = context
|
||||||
|
|
||||||
|
=======
|
||||||
|
if stop_event is not None:
|
||||||
|
if debug:
|
||||||
|
warnings.simplefilter('default')
|
||||||
|
warnings.warn("stop_event will be removed from future versions.",
|
||||||
|
DeprecationWarning)
|
||||||
|
>>>>>>> remove stop_event
|
||||||
if loop is not None:
|
if loop is not None:
|
||||||
if debug:
|
if debug:
|
||||||
warnings.simplefilter('default')
|
warnings.simplefilter('default')
|
||||||
|
|
|
@ -4,10 +4,13 @@ import traceback
|
||||||
import warnings
|
import warnings
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import isawaitable
|
from inspect import isawaitable
|
||||||
from multiprocessing import Process, Event
|
from multiprocessing import Process
|
||||||
from os import set_inheritable
|
from os import set_inheritable
|
||||||
from signal import SIGTERM, SIGINT
|
from signal import (
|
||||||
from signal import signal as signal_func
|
SIGTERM, SIGINT,
|
||||||
|
signal as signal_func,
|
||||||
|
Signals
|
||||||
|
)
|
||||||
from socket import socket, SOL_SOCKET, SO_REUSEADDR
|
from socket import socket, SOL_SOCKET, SO_REUSEADDR
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
@ -421,7 +424,7 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
|
|
||||||
def serve_multiple(server_settings, workers, stop_event=None):
|
def serve_multiple(server_settings, workers):
|
||||||
"""Start multiple server processes simultaneously. Stop on interrupt
|
"""Start multiple server processes simultaneously. Stop on interrupt
|
||||||
and terminate signals, and drain connections when complete.
|
and terminate signals, and drain connections when complete.
|
||||||
|
|
||||||
|
@ -448,11 +451,12 @@ def serve_multiple(server_settings, workers, stop_event=None):
|
||||||
server_settings['host'] = None
|
server_settings['host'] = None
|
||||||
server_settings['port'] = None
|
server_settings['port'] = None
|
||||||
|
|
||||||
if stop_event is None:
|
def sig_handler(signal, frame):
|
||||||
stop_event = Event()
|
log.info("Received signal {}. Shutting down.".format(
|
||||||
|
Signals(signal).name))
|
||||||
|
|
||||||
signal_func(SIGINT, lambda s, f: stop_event.set())
|
signal_func(SIGINT, lambda s, f: sig_handler(s, f))
|
||||||
signal_func(SIGTERM, lambda s, f: stop_event.set())
|
signal_func(SIGTERM, lambda s, f: sig_handler(s, f))
|
||||||
|
|
||||||
processes = []
|
processes = []
|
||||||
for _ in range(workers):
|
for _ in range(workers):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user