Added warning messages
This commit is contained in:
parent
e6e0cd6528
commit
b3ff3926db
26
sanic/app.py
26
sanic/app.py
@ -15,6 +15,7 @@ from asyncio import (
|
|||||||
)
|
)
|
||||||
from asyncio.futures import Future
|
from asyncio.futures import Future
|
||||||
from collections import defaultdict, deque
|
from collections import defaultdict, deque
|
||||||
|
from distutils.util import strtobool
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from inspect import isawaitable
|
from inspect import isawaitable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -49,6 +50,7 @@ from sanic.asgi import ASGIApp
|
|||||||
from sanic.base import BaseSanic
|
from sanic.base import BaseSanic
|
||||||
from sanic.blueprint_group import BlueprintGroup
|
from sanic.blueprint_group import BlueprintGroup
|
||||||
from sanic.blueprints import Blueprint
|
from sanic.blueprints import Blueprint
|
||||||
|
from sanic.compat import OS_IS_WINDOWS
|
||||||
from sanic.config import BASE_LOGO, SANIC_PREFIX, Config
|
from sanic.config import BASE_LOGO, SANIC_PREFIX, Config
|
||||||
from sanic.exceptions import (
|
from sanic.exceptions import (
|
||||||
InvalidUsage,
|
InvalidUsage,
|
||||||
@ -206,8 +208,28 @@ class Sanic(BaseSanic, metaclass=TouchUpMeta):
|
|||||||
if self.config.REGISTER:
|
if self.config.REGISTER:
|
||||||
self.__class__.register_app(self)
|
self.__class__.register_app(self)
|
||||||
|
|
||||||
if self.config.USE_UVLOOP:
|
if self.config.USE_UVLOOP and not OS_IS_WINDOWS:
|
||||||
use_uvloop()
|
uvloop_success = use_uvloop()
|
||||||
|
|
||||||
|
# uvloop requested, but not installed
|
||||||
|
if not uvloop_success:
|
||||||
|
error_logger.warning(
|
||||||
|
"You are trying to use uvloop, but uvloop is not "
|
||||||
|
"installed in your system. In order to use uvloop "
|
||||||
|
"you must first install it. Otherwise, you can disable "
|
||||||
|
"uvloop completely by setting the 'USE_UVLOOP' configuration "
|
||||||
|
"value to false. The app will now run without uvloop."
|
||||||
|
)
|
||||||
|
|
||||||
|
# uvloop requested and installed, but opted-out during install
|
||||||
|
elif strtobool(os.environ.get("SANIC_NO_UVLOOP", "no")):
|
||||||
|
error_logger.warning(
|
||||||
|
"You are running the app using uvloop, but we've noticed "
|
||||||
|
"that the 'SANIC_NO_UVLOOP' environment variable "
|
||||||
|
"(used to opt-out of installing uvloop with Sanic) "
|
||||||
|
"is set to true. If you want to disable uvloop with Sanic, "
|
||||||
|
"set the 'USE_UVLOOP' configuration value to false."
|
||||||
|
)
|
||||||
|
|
||||||
self.router.ctx.app = self
|
self.router.ctx.app = self
|
||||||
self.signal_router.ctx.app = self
|
self.signal_router.ctx.app = self
|
||||||
|
@ -6,7 +6,7 @@ from sanic.server.protocols.http_protocol import HttpProtocol
|
|||||||
from sanic.server.runners import serve, serve_multiple, serve_single
|
from sanic.server.runners import serve, serve_multiple, serve_single
|
||||||
|
|
||||||
|
|
||||||
def use_uvloop():
|
def use_uvloop() -> bool:
|
||||||
"""
|
"""
|
||||||
Use uvloop (if available) instead of the default
|
Use uvloop (if available) instead of the default
|
||||||
asyncio loop.
|
asyncio loop.
|
||||||
@ -19,7 +19,8 @@ def use_uvloop():
|
|||||||
):
|
):
|
||||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user