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:
L. Kärkkäinen 2020-03-21 20:42:35 +02:00
parent 036c1d7019
commit dc5d682448
2 changed files with 16 additions and 9 deletions

View File

@ -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:
# Default auto_reload to false logger.warning(f"Sanic.run ignored arguments {kwargs.keys()}")
auto_reload = False if auto_reload is None:
# If debug is set, default it to true (unless on windows) # Default auto_reload to false
if debug and os.name == "posix": auto_reload = False
auto_reload = True # If debug is set, default it to true (unless on windows)
# Allow for overriding either of the defaults if debug and os.name == "posix":
auto_reload = kwargs.get("auto_reload", auto_reload) auto_reload = True
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

View File

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