Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move granian to the sidelines #5010

Merged
merged 3 commits into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ dependencies = [
"distro >=1.8.0,<2.0; platform_system == 'Linux'",
"fastapi >=0.96.0,!=0.111.0,!=0.111.1",
"granian[reload] >=2.0.0",
"gunicorn >=23.0.0,<24.0.0",
"httpx >=0.25.1,<1.0",
"jinja2 >=3.1.2,<4.0",
"lazy_loader >=0.4",
@@ -46,6 +47,7 @@ dependencies = [
"twine >=4.0.0,<7.0",
"typer >=0.15.1,<1.0",
"typing_extensions >=4.6.0",
"uvicorn >=0.20.0",
"wheel >=0.42.0,<1.0",
"wrapt >=1.17.0,<2.0",
]
@@ -161,5 +163,4 @@ dev = [
"ruff ==0.11.0",
"selenium >=4.11.0,<5.0",
"toml >=0.10.2,<1.0",
"uvicorn >=0.20.0",
]
2 changes: 1 addition & 1 deletion reflex/app.py
Original file line number Diff line number Diff line change
@@ -968,7 +968,7 @@ def _should_compile(self) -> bool:
# Check the nocompile file.
if nocompile.exists():
# Delete the nocompile file
nocompile.unlink()
nocompile.unlink(missing_ok=True)
return False

# By default, compile the app.
72 changes: 39 additions & 33 deletions reflex/utils/exec.py
Original file line number Diff line number Diff line change
@@ -189,9 +189,11 @@ def run_frontend_prod(root: Path, port: str, backend_present: bool = True):

@once
def _warn_user_about_uvicorn():
console.warn(
"Using Uvicorn for backend as it is installed. This behavior will change in 0.8.0 to use Granian by default."
)
# When we eventually switch to Granian by default, we should enable this warning.
if False:
console.warn(
"Using Uvicorn for backend as it is installed. This behavior will change in 0.8.0 to use Granian by default."
)


def should_use_granian():
@@ -357,70 +359,74 @@ def run_granian_backend(host: str, port: int, loglevel: LogLevel):
).serve()


def _deprecate_asgi_config(
config_name: str,
reason: str = "",
):
# When we eventually switch to Granian by default, we should enable this deprecation.
if False:
console.deprecate(
f"config.{config_name}",
reason=reason,
deprecation_version="0.7.5",
removal_version="0.8.0",
)


@once
def _get_backend_workers():
from reflex.utils import processes

config = get_config()

gunicorn_workers = config.gunicorn_workers or 0

if config.gunicorn_workers is not None:
console.deprecate(
"config.gunicorn_workers",
reason="If you're using Granian, use GRANIAN_WORKERS instead.",
deprecation_version="0.7.4",
removal_version="0.8.0",
_deprecate_asgi_config(
"gunicorn_workers",
"If you're using Granian, use GRANIAN_WORKERS instead.",
)

return (
processes.get_num_workers()
if not config.gunicorn_workers
else config.gunicorn_workers
)
return gunicorn_workers if gunicorn_workers else processes.get_num_workers()


@once
def _get_backend_timeout():
config = get_config()

timeout = config.timeout or 120

if config.timeout is not None:
console.deprecate(
"config.timeout",
reason="If you're using Granian, use GRANIAN_WORKERS_LIFETIME instead.",
deprecation_version="0.7.4",
removal_version="0.8.0",
_deprecate_asgi_config(
"timeout",
"If you're using Granian, use GRANIAN_WORKERS_LIFETIME instead.",
)

return config.timeout
return timeout


@once
def _get_backend_max_requests():
config = get_config()

gunicorn_max_requests = config.gunicorn_max_requests or 120

if config.gunicorn_max_requests is not None:
console.deprecate(
"config.gunicorn_max_requests",
reason="",
deprecation_version="0.7.4",
removal_version="0.8.0",
)
_deprecate_asgi_config("gunicorn_max_requests")

return config.gunicorn_max_requests
return gunicorn_max_requests


@once
def _get_backend_max_requests_jitter():
config = get_config()

gunicorn_max_requests_jitter = config.gunicorn_max_requests_jitter or 25

if config.gunicorn_max_requests_jitter is not None:
console.deprecate(
"config.gunicorn_max_requests_jitter",
reason="",
deprecation_version="0.7.4",
removal_version="0.8.0",
)
_deprecate_asgi_config("gunicorn_max_requests_jitter")

return config.gunicorn_max_requests_jitter
return gunicorn_max_requests_jitter


def run_backend_prod(
20 changes: 17 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.