Skip to content

Commit

Permalink
app.run argument handling: added server kwargs (alike create_server),…
Browse files Browse the repository at this point in the history
… added warning on extra kwargs, made auto_reload explicit argument. Another go at Windows tests
  • Loading branch information
Tronic committed Mar 21, 2020
1 parent 036c1d7 commit dc5d682
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ def run(
stop_event: Any = None,
register_sys_signals: bool = True,
access_log: Optional[bool] = None,
auto_reload = None,
asyncio_server_kwargs = None,
**kwargs: Any,
) -> None:
"""Run the HTTP Server and listen until keyboard interrupt or term
Expand Down Expand Up @@ -1126,6 +1128,9 @@ def run(
:type register_sys_signals: bool
:param access_log: Enables writing access logs (slows server)
:type access_log: bool
:param asyncio_server_kwargs: key-value arguments for
asyncio/uvloop create_server method
:type asyncio_server_kwargs: dict
:return: Nothing
"""
if "loop" in kwargs:
Expand All @@ -1135,14 +1140,14 @@ def run(
"https://sanic.readthedocs.io/en/latest/sanic/deploying.html"
"#asynchronous-support"
)

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

if sock is None:
host, port = host or "127.0.0.1", port or 8000
Expand Down Expand Up @@ -1174,6 +1179,8 @@ def run(
register_sys_signals=register_sys_signals,
auto_reload=auto_reload,
)
if asyncio_server_kwargs:
server_settings["asyncio_server_kwargs"] = asyncio_server_kwargs

try:
self.is_running = True
Expand Down
2 changes: 1 addition & 1 deletion sanic/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def error_handler(request, exception):
server_kwargs = dict(
host=host or self.host,
port=self.port,
reuse_port=True, # Try to avoid test failures on Windows
asyncio_server_kwargs=dict(reuse_address=True),
**server_kwargs,
)
host, port = host or self.host, self.port
Expand Down

0 comments on commit dc5d682

Please sign in to comment.