浏览代码

move granian to the sidelines (#5010)

* move granian to the sidelines

* what

* oops as well
Khaleel Al-Adhami 1 月之前
父节点
当前提交
1121cb7f5c
共有 4 个文件被更改,包括 59 次插入38 次删除
  1. 2 1
      pyproject.toml
  2. 1 1
      reflex/app.py
  3. 39 33
      reflex/utils/exec.py
  4. 17 3
      uv.lock

+ 2 - 1
pyproject.toml

@@ -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",
 ]

+ 1 - 1
reflex/app.py

@@ -968,7 +968,7 @@ class App(MiddlewareMixin, LifespanMixin):
         # 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.

+ 39 - 33
reflex/utils/exec.py

@@ -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(

+ 17 - 3
uv.lock

@@ -556,6 +556,18 @@ wheels = [
     { url = "https://files.pythonhosted.org/packages/ac/38/08cc303ddddc4b3d7c628c3039a61a3aae36c241ed01393d00c2fd663473/greenlet-3.1.1-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:411f015496fec93c1c8cd4e5238da364e1da7a124bcb293f085bf2860c32c6f6", size = 1142112 },
 ]
 
+[[package]]
+name = "gunicorn"
+version = "23.0.0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+    { name = "packaging" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/34/72/9614c465dc206155d93eff0ca20d42e1e35afc533971379482de953521a4/gunicorn-23.0.0.tar.gz", hash = "sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec", size = 375031 }
+wheels = [
+    { url = "https://files.pythonhosted.org/packages/cb/7d/6dac2a6e1eba33ee43f318edbed4ff29151a49b5d37f080aad1e6469bca4/gunicorn-23.0.0-py3-none-any.whl", hash = "sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d", size = 85029 },
+]
+
 [[package]]
 name = "h11"
 version = "0.14.0"
@@ -628,7 +640,7 @@ name = "importlib-metadata"
 version = "8.6.1"
 source = { registry = "https://pypi.org/simple" }
 dependencies = [
-    { name = "zipp" },
+    { name = "zipp", marker = "python_full_version < '3.12'" },
 ]
 sdist = { url = "https://files.pythonhosted.org/packages/33/08/c1395a292bb23fd03bdf572a1357c5a733d3eecbab877641ceacab23db6e/importlib_metadata-8.6.1.tar.gz", hash = "sha256:310b41d755445d74569f993ccfc22838295d9fe005425094fad953d7f15c8580", size = 55767 }
 wheels = [
@@ -1706,6 +1718,7 @@ dependencies = [
     { name = "distro", marker = "sys_platform == 'linux'" },
     { name = "fastapi" },
     { name = "granian", extra = ["reload"] },
+    { name = "gunicorn" },
     { name = "httpx" },
     { name = "jinja2" },
     { name = "lazy-loader" },
@@ -1726,6 +1739,7 @@ dependencies = [
     { name = "twine" },
     { name = "typer" },
     { name = "typing-extensions" },
+    { name = "uvicorn" },
     { name = "wheel" },
     { name = "wrapt" },
 ]
@@ -1757,7 +1771,6 @@ dev = [
     { name = "ruff" },
     { name = "selenium" },
     { name = "toml" },
-    { name = "uvicorn" },
 ]
 
 [package.metadata]
@@ -1768,6 +1781,7 @@ requires-dist = [
     { name = "distro", marker = "sys_platform == 'linux'", specifier = ">=1.8.0,<2.0" },
     { name = "fastapi", specifier = ">=0.96.0,!=0.111.0,!=0.111.1" },
     { name = "granian", extras = ["reload"], specifier = ">=2.0.0" },
+    { name = "gunicorn", specifier = ">=23.0.0,<24.0.0" },
     { name = "httpx", specifier = ">=0.25.1,<1.0" },
     { name = "jinja2", specifier = ">=3.1.2,<4.0" },
     { name = "lazy-loader", specifier = ">=0.4" },
@@ -1788,6 +1802,7 @@ requires-dist = [
     { name = "twine", specifier = ">=4.0.0,<7.0" },
     { name = "typer", specifier = ">=0.15.1,<1.0" },
     { name = "typing-extensions", specifier = ">=4.6.0" },
+    { name = "uvicorn", specifier = ">=0.20.0" },
     { name = "wheel", specifier = ">=0.42.0,<1.0" },
     { name = "wrapt", specifier = ">=1.17.0,<2.0" },
 ]
@@ -1819,7 +1834,6 @@ dev = [
     { name = "ruff", specifier = "==0.11.0" },
     { name = "selenium", specifier = ">=4.11.0,<5.0" },
     { name = "toml", specifier = ">=0.10.2,<1.0" },
-    { name = "uvicorn", specifier = ">=0.20.0" },
 ]
 
 [[package]]