app.run argument handling: added server kwargs (alike create_server), added warning on extra kwargs, made auto_reload explicit argument. Another go at Windows tests
This commit is contained in:
parent
036c1d7019
commit
dc5d682448
13
sanic/app.py
13
sanic/app.py
|
@ -1096,6 +1096,8 @@ class Sanic:
|
||||||
stop_event: Any = None,
|
stop_event: Any = None,
|
||||||
register_sys_signals: bool = True,
|
register_sys_signals: bool = True,
|
||||||
access_log: Optional[bool] = None,
|
access_log: Optional[bool] = None,
|
||||||
|
auto_reload = None,
|
||||||
|
asyncio_server_kwargs = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run the HTTP Server and listen until keyboard interrupt or term
|
"""Run the HTTP Server and listen until keyboard interrupt or term
|
||||||
|
@ -1126,6 +1128,9 @@ class Sanic:
|
||||||
:type register_sys_signals: bool
|
:type register_sys_signals: bool
|
||||||
:param access_log: Enables writing access logs (slows server)
|
:param access_log: Enables writing access logs (slows server)
|
||||||
:type access_log: bool
|
:type access_log: bool
|
||||||
|
:param asyncio_server_kwargs: key-value arguments for
|
||||||
|
asyncio/uvloop create_server method
|
||||||
|
:type asyncio_server_kwargs: dict
|
||||||
:return: Nothing
|
:return: Nothing
|
||||||
"""
|
"""
|
||||||
if "loop" in kwargs:
|
if "loop" in kwargs:
|
||||||
|
@ -1135,14 +1140,14 @@ class Sanic:
|
||||||
"https://sanic.readthedocs.io/en/latest/sanic/deploying.html"
|
"https://sanic.readthedocs.io/en/latest/sanic/deploying.html"
|
||||||
"#asynchronous-support"
|
"#asynchronous-support"
|
||||||
)
|
)
|
||||||
|
if kwargs:
|
||||||
|
logger.warning(f"Sanic.run ignored arguments {kwargs.keys()}")
|
||||||
|
if auto_reload is None:
|
||||||
# Default auto_reload to false
|
# Default auto_reload to false
|
||||||
auto_reload = False
|
auto_reload = False
|
||||||
# If debug is set, default it to true (unless on windows)
|
# If debug is set, default it to true (unless on windows)
|
||||||
if debug and os.name == "posix":
|
if debug and os.name == "posix":
|
||||||
auto_reload = True
|
auto_reload = True
|
||||||
# Allow for overriding either of the defaults
|
|
||||||
auto_reload = kwargs.get("auto_reload", auto_reload)
|
|
||||||
|
|
||||||
if sock is None:
|
if sock is None:
|
||||||
host, port = host or "127.0.0.1", port or 8000
|
host, port = host or "127.0.0.1", port or 8000
|
||||||
|
@ -1174,6 +1179,8 @@ class Sanic:
|
||||||
register_sys_signals=register_sys_signals,
|
register_sys_signals=register_sys_signals,
|
||||||
auto_reload=auto_reload,
|
auto_reload=auto_reload,
|
||||||
)
|
)
|
||||||
|
if asyncio_server_kwargs:
|
||||||
|
server_settings["asyncio_server_kwargs"] = asyncio_server_kwargs
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.is_running = True
|
self.is_running = True
|
||||||
|
|
|
@ -97,7 +97,7 @@ class SanicTestClient:
|
||||||
server_kwargs = dict(
|
server_kwargs = dict(
|
||||||
host=host or self.host,
|
host=host or self.host,
|
||||||
port=self.port,
|
port=self.port,
|
||||||
reuse_port=True, # Try to avoid test failures on Windows
|
asyncio_server_kwargs=dict(reuse_address=True),
|
||||||
**server_kwargs,
|
**server_kwargs,
|
||||||
)
|
)
|
||||||
host, port = host or self.host, self.port
|
host, port = host or self.host, self.port
|
||||||
|
|
Loading…
Reference in New Issue
Block a user