Merge pull request #681 from 38elements/deprecation
Remove before_start, before_stop, after_start and after_stop
This commit is contained in:
commit
a480110d43
53
sanic/app.py
53
sanic/app.py
|
@ -516,8 +516,7 @@ class Sanic:
|
||||||
# Execution
|
# Execution
|
||||||
# -------------------------------------------------------------------- #
|
# -------------------------------------------------------------------- #
|
||||||
|
|
||||||
def run(self, host="127.0.0.1", port=8000, debug=False, before_start=None,
|
def run(self, host="127.0.0.1", port=8000, debug=False, ssl=None,
|
||||||
after_start=None, before_stop=None, after_stop=None, ssl=None,
|
|
||||||
sock=None, workers=1, loop=None, protocol=None,
|
sock=None, workers=1, loop=None, protocol=None,
|
||||||
backlog=100, stop_event=None, register_sys_signals=True,
|
backlog=100, stop_event=None, register_sys_signals=True,
|
||||||
log_config=LOGGING):
|
log_config=LOGGING):
|
||||||
|
@ -527,14 +526,6 @@ class Sanic:
|
||||||
:param host: Address to host on
|
:param host: Address to host on
|
||||||
:param port: Port to host on
|
:param port: Port to host on
|
||||||
:param debug: Enables debug output (slows server)
|
:param debug: Enables debug output (slows server)
|
||||||
:param before_start: Functions to be executed before the server starts
|
|
||||||
accepting connections
|
|
||||||
:param after_start: Functions to be executed after the server starts
|
|
||||||
accepting connections
|
|
||||||
:param before_stop: Functions to be executed when a stop signal is
|
|
||||||
received before it is respected
|
|
||||||
:param after_stop: Functions to be executed when all requests are
|
|
||||||
complete
|
|
||||||
:param ssl: SSLContext, or location of certificate and key
|
:param ssl: SSLContext, or location of certificate and key
|
||||||
for SSL encryption of worker(s)
|
for SSL encryption of worker(s)
|
||||||
:param sock: Socket for the server to accept connections from
|
:param sock: Socket for the server to accept connections from
|
||||||
|
@ -558,10 +549,8 @@ class Sanic:
|
||||||
warnings.warn("stop_event will be removed from future versions.",
|
warnings.warn("stop_event will be removed from future versions.",
|
||||||
DeprecationWarning)
|
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, ssl=ssl, sock=sock,
|
||||||
after_start=after_start, before_stop=before_stop,
|
workers=workers, loop=loop, protocol=protocol, backlog=backlog,
|
||||||
after_stop=after_stop, ssl=ssl, sock=sock, workers=workers,
|
|
||||||
loop=loop, protocol=protocol, backlog=backlog,
|
|
||||||
register_sys_signals=register_sys_signals,
|
register_sys_signals=register_sys_signals,
|
||||||
has_log=log_config is not None)
|
has_log=log_config is not None)
|
||||||
|
|
||||||
|
@ -588,9 +577,7 @@ class Sanic:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
async def create_server(self, host="127.0.0.1", port=8000, debug=False,
|
async def create_server(self, host="127.0.0.1", port=8000, debug=False,
|
||||||
before_start=None, after_start=None,
|
ssl=None, sock=None, loop=None, protocol=None,
|
||||||
before_stop=None, after_stop=None, ssl=None,
|
|
||||||
sock=None, loop=None, protocol=None,
|
|
||||||
backlog=100, stop_event=None,
|
backlog=100, stop_event=None,
|
||||||
log_config=LOGGING):
|
log_config=LOGGING):
|
||||||
"""Asynchronous version of `run`.
|
"""Asynchronous version of `run`.
|
||||||
|
@ -609,9 +596,7 @@ class Sanic:
|
||||||
warnings.warn("stop_event will be removed from future versions.",
|
warnings.warn("stop_event will be removed from future versions.",
|
||||||
DeprecationWarning)
|
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, ssl=ssl, sock=sock,
|
||||||
after_start=after_start, before_stop=before_stop,
|
|
||||||
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, run_async=True,
|
backlog=backlog, run_async=True,
|
||||||
has_log=log_config is not None)
|
has_log=log_config is not None)
|
||||||
|
@ -641,8 +626,7 @@ class Sanic:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _helper(self, host="127.0.0.1", port=8000, debug=False,
|
def _helper(self, host="127.0.0.1", port=8000, debug=False,
|
||||||
before_start=None, after_start=None, before_stop=None,
|
ssl=None, sock=None, workers=1, loop=None,
|
||||||
after_stop=None, ssl=None, sock=None, workers=1, loop=None,
|
|
||||||
protocol=HttpProtocol, backlog=100, stop_event=None,
|
protocol=HttpProtocol, backlog=100, stop_event=None,
|
||||||
register_sys_signals=True, run_async=False, has_log=True):
|
register_sys_signals=True, run_async=False, has_log=True):
|
||||||
"""Helper function used by `run` and `create_server`."""
|
"""Helper function used by `run` and `create_server`."""
|
||||||
|
@ -669,16 +653,6 @@ class Sanic:
|
||||||
"pull/335 has more information.",
|
"pull/335 has more information.",
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
|
|
||||||
# Deprecate this
|
|
||||||
if any(arg is not None for arg in (after_stop, after_start,
|
|
||||||
before_start, before_stop)):
|
|
||||||
if debug:
|
|
||||||
warnings.simplefilter('default')
|
|
||||||
warnings.warn("Passing a before_start, before_stop, after_start or"
|
|
||||||
"after_stop callback will be deprecated in next "
|
|
||||||
"major version after 0.4.0",
|
|
||||||
DeprecationWarning)
|
|
||||||
|
|
||||||
self.error_handler.debug = debug
|
self.error_handler.debug = debug
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
|
|
||||||
|
@ -706,18 +680,13 @@ class Sanic:
|
||||||
# Register start/stop events
|
# Register start/stop events
|
||||||
# -------------------------------------------- #
|
# -------------------------------------------- #
|
||||||
|
|
||||||
for event_name, settings_name, reverse, args in (
|
for event_name, settings_name, reverse in (
|
||||||
("before_server_start", "before_start", False, before_start),
|
("before_server_start", "before_start", False),
|
||||||
("after_server_start", "after_start", False, after_start),
|
("after_server_start", "after_start", False),
|
||||||
("before_server_stop", "before_stop", True, before_stop),
|
("before_server_stop", "before_stop", True),
|
||||||
("after_server_stop", "after_stop", True, after_stop),
|
("after_server_stop", "after_stop", True),
|
||||||
):
|
):
|
||||||
listeners = self.listeners[event_name].copy()
|
listeners = self.listeners[event_name].copy()
|
||||||
if args:
|
|
||||||
if callable(args):
|
|
||||||
listeners.append(args)
|
|
||||||
else:
|
|
||||||
listeners.extend(args)
|
|
||||||
if reverse:
|
if reverse:
|
||||||
listeners.reverse()
|
listeners.reverse()
|
||||||
# Prepend sanic to the arguments when listeners are triggered
|
# Prepend sanic to the arguments when listeners are triggered
|
||||||
|
|
Loading…
Reference in New Issue
Block a user