Bladeren bron

(dev mode) start backend without waiting for page compilation (#2549)

* start backend without waiting for page compilation

* remove prints for measuring time saved

* pin tighter on uvicorn
jackie-pc 1 jaar geleden
bovenliggende
commit
a4c8c72177
3 gewijzigde bestanden met toevoegingen van 437 en 398 verwijderingen
  1. 426 392
      poetry.lock
  2. 1 4
      pyproject.toml
  3. 10 2
      reflex/app_module_for_backend.py

File diff suppressed because it is too large
+ 426 - 392
poetry.lock


+ 1 - 4
pyproject.toml

@@ -40,10 +40,7 @@ redis = "^4.3.5"
 rich = "^13.0.0"
 rich = "^13.0.0"
 sqlmodel = "^0.0.14"
 sqlmodel = "^0.0.14"
 typer = ">=0.4.2,<1"
 typer = ">=0.4.2,<1"
-uvicorn = [
-    {version = "^0.24.0", python = ">=3.12"},
-    {version = "^0.20.0", python = "<3.12"},
-]
+uvicorn = "^0.27.0"
 watchdog = "^2.3.1"
 watchdog = "^2.3.1"
 watchfiles = "^0.19.0"
 watchfiles = "^0.19.0"
 starlette-admin = "^0.9.0"
 starlette-admin = "^0.9.0"

+ 10 - 2
reflex/app_module_for_backend.py

@@ -1,13 +1,21 @@
 """Shims the real reflex app module for running backend server (uvicorn or gunicorn).
 """Shims the real reflex app module for running backend server (uvicorn or gunicorn).
 Only the app attribute is explicitly exposed.
 Only the app attribute is explicitly exposed.
 """
 """
+from concurrent.futures import ThreadPoolExecutor
+
 from reflex import constants
 from reflex import constants
-from reflex.utils.prerequisites import get_compiled_app
+from reflex.utils.prerequisites import get_app, get_compiled_app
 
 
 if "app" != constants.CompileVars.APP:
 if "app" != constants.CompileVars.APP:
     raise AssertionError("unexpected variable name for 'app'")
     raise AssertionError("unexpected variable name for 'app'")
-app = getattr(get_compiled_app(), constants.CompileVars.APP)
+
+app_module = get_app(reload=False)
+app = getattr(app_module, constants.CompileVars.APP)
+ThreadPoolExecutor(max_workers=1).submit(app.compile_)
 
 
 # ensure only "app" is exposed.
 # ensure only "app" is exposed.
+del app_module
+del get_app
 del get_compiled_app
 del get_compiled_app
 del constants
 del constants
+del ThreadPoolExecutor

Some files were not shown because too many files changed in this diff