Only change loop policy in non-async methods
This commit is contained in:
parent
796892de52
commit
877f5e6aef
16
sanic/app.py
16
sanic/app.py
@ -1102,6 +1102,9 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
register_sys_signals=register_sys_signals,
|
register_sys_signals=register_sys_signals,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.config.USE_UVLOOP:
|
||||||
|
use_uvloop()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.is_running = True
|
self.is_running = True
|
||||||
self.is_stopping = False
|
self.is_stopping = False
|
||||||
@ -1213,7 +1216,7 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
ssl=ssl,
|
ssl=ssl,
|
||||||
sock=sock,
|
sock=sock,
|
||||||
unix=unix,
|
unix=unix,
|
||||||
loop=True,
|
loop=get_event_loop(),
|
||||||
protocol=protocol,
|
protocol=protocol,
|
||||||
backlog=backlog,
|
backlog=backlog,
|
||||||
run_async=return_asyncio_server,
|
run_async=return_asyncio_server,
|
||||||
@ -1323,7 +1326,7 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
sock: Optional[socket] = None,
|
sock: Optional[socket] = None,
|
||||||
unix: Optional[str] = None,
|
unix: Optional[str] = None,
|
||||||
workers: int = 1,
|
workers: int = 1,
|
||||||
loop: Union[AbstractEventLoop, bool] = None,
|
loop: AbstractEventLoop = None,
|
||||||
protocol: Type[Protocol] = HttpProtocol,
|
protocol: Type[Protocol] = HttpProtocol,
|
||||||
backlog: int = 100,
|
backlog: int = 100,
|
||||||
register_sys_signals: bool = True,
|
register_sys_signals: bool = True,
|
||||||
@ -1356,13 +1359,6 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
display_host = f"[{host}]" if ":" in host else host
|
display_host = f"[{host}]" if ":" in host else host
|
||||||
serve_location = f"{proto}://{display_host}:{port}"
|
serve_location = f"{proto}://{display_host}:{port}"
|
||||||
|
|
||||||
if not isinstance(loop, AbstractEventLoop):
|
|
||||||
if self.config.USE_UVLOOP:
|
|
||||||
use_uvloop()
|
|
||||||
|
|
||||||
if loop is True:
|
|
||||||
loop = get_event_loop()
|
|
||||||
|
|
||||||
ssl = process_to_context(ssl)
|
ssl = process_to_context(ssl)
|
||||||
|
|
||||||
server_settings = {
|
server_settings = {
|
||||||
@ -1459,8 +1455,6 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
details: https://asgi.readthedocs.io/en/latest
|
details: https://asgi.readthedocs.io/en/latest
|
||||||
"""
|
"""
|
||||||
self.asgi = True
|
self.asgi = True
|
||||||
if self.config.USE_UVLOOP:
|
|
||||||
use_uvloop()
|
|
||||||
self.motd("")
|
self.motd("")
|
||||||
self._asgi_app = await ASGIApp.create(self, scope, receive, send)
|
self._asgi_app = await ASGIApp.create(self, scope, receive, send)
|
||||||
asgi_app = self._asgi_app
|
asgi_app = self._asgi_app
|
||||||
|
@ -440,6 +440,7 @@ def test_custom_context():
|
|||||||
|
|
||||||
assert app.ctx == ctx
|
assert app.ctx == ctx
|
||||||
|
|
||||||
|
|
||||||
def test_uvloop_usage(app, monkeypatch):
|
def test_uvloop_usage(app, monkeypatch):
|
||||||
@app.get("/test")
|
@app.get("/test")
|
||||||
def handler(request):
|
def handler(request):
|
||||||
@ -457,7 +458,7 @@ def test_uvloop_usage(app, monkeypatch):
|
|||||||
use_uvloop.assert_called_once()
|
use_uvloop.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_uvloop_usage_with_create_server(app, monkeypatch):
|
def test_uvloop_is_ignored_with_create_server(app, monkeypatch):
|
||||||
@app.get("/test")
|
@app.get("/test")
|
||||||
def handler(request):
|
def handler(request):
|
||||||
return text("ok")
|
return text("ok")
|
||||||
@ -481,7 +482,8 @@ def test_uvloop_usage_with_create_server(app, monkeypatch):
|
|||||||
asyncio_server_kwargs=dict(start_serving=False)
|
asyncio_server_kwargs=dict(start_serving=False)
|
||||||
)
|
)
|
||||||
loop.run_until_complete(asyncio_srv_coro)
|
loop.run_until_complete(asyncio_srv_coro)
|
||||||
use_uvloop.assert_called_once()
|
use_uvloop.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_cannot_run_fast_and_workers(app):
|
def test_cannot_run_fast_and_workers(app):
|
||||||
message = "You cannot use both fast=True and workers=X"
|
message = "You cannot use both fast=True and workers=X"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user