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,
|
||||
)
|
||||
|
||||
if self.config.USE_UVLOOP:
|
||||
use_uvloop()
|
||||
|
||||
try:
|
||||
self.is_running = True
|
||||
self.is_stopping = False
|
||||
@ -1213,7 +1216,7 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
||||
ssl=ssl,
|
||||
sock=sock,
|
||||
unix=unix,
|
||||
loop=True,
|
||||
loop=get_event_loop(),
|
||||
protocol=protocol,
|
||||
backlog=backlog,
|
||||
run_async=return_asyncio_server,
|
||||
@ -1323,7 +1326,7 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
||||
sock: Optional[socket] = None,
|
||||
unix: Optional[str] = None,
|
||||
workers: int = 1,
|
||||
loop: Union[AbstractEventLoop, bool] = None,
|
||||
loop: AbstractEventLoop = None,
|
||||
protocol: Type[Protocol] = HttpProtocol,
|
||||
backlog: int = 100,
|
||||
register_sys_signals: bool = True,
|
||||
@ -1356,13 +1359,6 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
||||
display_host = f"[{host}]" if ":" in host else host
|
||||
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)
|
||||
|
||||
server_settings = {
|
||||
@ -1459,8 +1455,6 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
||||
details: https://asgi.readthedocs.io/en/latest
|
||||
"""
|
||||
self.asgi = True
|
||||
if self.config.USE_UVLOOP:
|
||||
use_uvloop()
|
||||
self.motd("")
|
||||
self._asgi_app = await ASGIApp.create(self, scope, receive, send)
|
||||
asgi_app = self._asgi_app
|
||||
|
@ -440,6 +440,7 @@ def test_custom_context():
|
||||
|
||||
assert app.ctx == ctx
|
||||
|
||||
|
||||
def test_uvloop_usage(app, monkeypatch):
|
||||
@app.get("/test")
|
||||
def handler(request):
|
||||
@ -457,7 +458,7 @@ def test_uvloop_usage(app, monkeypatch):
|
||||
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")
|
||||
def handler(request):
|
||||
return text("ok")
|
||||
@ -481,7 +482,8 @@ def test_uvloop_usage_with_create_server(app, monkeypatch):
|
||||
asyncio_server_kwargs=dict(start_serving=False)
|
||||
)
|
||||
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):
|
||||
message = "You cannot use both fast=True and workers=X"
|
||||
|
Loading…
x
Reference in New Issue
Block a user