Skip to content

Commit

Permalink
fix: sideeffects created by changing fork to spawn (#2591)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidBySolo authored Oct 27, 2022
1 parent 6b9edfd commit 1c4925e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
URLBuildError,
)
from sanic.handlers import ErrorHandler
from sanic.helpers import _default
from sanic.helpers import Default
from sanic.http import Stage
from sanic.log import (
LOGGING_CONFIG_DEFAULTS,
Expand Down Expand Up @@ -1502,7 +1502,7 @@ async def _startup(self):

if self.state.is_debug and self.config.TOUCHUP is not True:
self.config.TOUCHUP = False
elif self.config.TOUCHUP is _default:
elif isinstance(self.config.TOUCHUP, Default):
self.config.TOUCHUP = True

# Setup routers
Expand Down
4 changes: 2 additions & 2 deletions sanic/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from sanic.compat import Header
from sanic.exceptions import ServerError
from sanic.helpers import _default
from sanic.helpers import Default
from sanic.http import Stage
from sanic.log import logger
from sanic.models.asgi import ASGIReceive, ASGIScope, ASGISend, MockTransport
Expand Down Expand Up @@ -61,7 +61,7 @@ async def startup(self) -> None:
await self.asgi_app.sanic_app._server_event("init", "before")
await self.asgi_app.sanic_app._server_event("init", "after")

if self.asgi_app.sanic_app.config.USE_UVLOOP is not _default:
if not isinstance(self.asgi_app.sanic_app.config.USE_UVLOOP, Default):
warnings.warn(
"You have set the USE_UVLOOP configuration option, but Sanic "
"cannot control the event loop when running in ASGI mode."
Expand Down
4 changes: 2 additions & 2 deletions sanic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ def _post_set(self, attr, value) -> None:

@property
def FALLBACK_ERROR_FORMAT(self) -> str:
if self._FALLBACK_ERROR_FORMAT is _default:
if isinstance(self._FALLBACK_ERROR_FORMAT, Default):
return DEFAULT_FORMAT
return self._FALLBACK_ERROR_FORMAT

@FALLBACK_ERROR_FORMAT.setter
def FALLBACK_ERROR_FORMAT(self, value):
self._check_error_format(value)
if (
self._FALLBACK_ERROR_FORMAT is not _default
not isinstance(self._FALLBACK_ERROR_FORMAT, Default)
and value != self._FALLBACK_ERROR_FORMAT
):
error_logger.warning(
Expand Down
7 changes: 4 additions & 3 deletions sanic/mixins/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from sanic.application.state import ApplicationServerInfo, Mode, ServerStage
from sanic.base.meta import SanicMeta
from sanic.compat import OS_IS_WINDOWS, is_atty
from sanic.helpers import _default
from sanic.helpers import Default
from sanic.http.constants import HTTP
from sanic.http.tls import get_ssl_context, process_to_context
from sanic.http.tls.context import SanicSSLContext
Expand Down Expand Up @@ -91,7 +91,8 @@ class StartupMixin(metaclass=SanicMeta):
def setup_loop(self):
if not self.asgi:
if self.config.USE_UVLOOP is True or (
self.config.USE_UVLOOP is _default and not OS_IS_WINDOWS
isinstance(self.config.USE_UVLOOP, Default)
and not OS_IS_WINDOWS
):
try_use_uvloop()
elif OS_IS_WINDOWS:
Expand Down Expand Up @@ -431,7 +432,7 @@ async def create_server(
run_async=return_asyncio_server,
)

if self.config.USE_UVLOOP is not _default:
if not isinstance(self.config.USE_UVLOOP, Default):
error_logger.warning(
"You are trying to change the uvloop configuration, but "
"this is only effective when using the run(...) method. "
Expand Down
6 changes: 4 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sanic.compat import OS_IS_WINDOWS
from sanic.config import Config
from sanic.exceptions import SanicException
from sanic.helpers import _default
from sanic.helpers import Default
from sanic.log import LOGGING_CONFIG_DEFAULTS
from sanic.response import text
from sanic.router import Route
Expand Down Expand Up @@ -497,7 +497,9 @@ def test_uvloop_cannot_never_called_with_create_server(caplog, monkeypatch):
)

counter = Counter([(r[1], r[2]) for r in caplog.record_tuples])
modified = sum(1 for app in apps if app.config.USE_UVLOOP is not _default)
modified = sum(
1 for app in apps if not isinstance(app.config.USE_UVLOOP, Default)
)

assert counter[(logging.WARNING, message)] == modified

Expand Down

0 comments on commit 1c4925e

Please sign in to comment.