From 434e794412acd59dd684ce5184b42bc63da396be Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Fri, 14 Feb 2025 18:18:58 -0800 Subject: [PATCH] granian is funny --- reflex/reflex.py | 5 ++++- reflex/utils/exec.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/reflex/reflex.py b/reflex/reflex.py index 410485551..717509efa 100644 --- a/reflex/reflex.py +++ b/reflex/reflex.py @@ -15,6 +15,7 @@ from reflex.config import environment, get_config from reflex.custom_components.custom_components import custom_components_cli from reflex.state import reset_disk_state_manager from reflex.utils import console, telemetry +from reflex.utils.exec import should_use_granian # Disable typer+rich integration for help panels typer.core.rich = None # pyright: ignore [reportPrivateImportUsage] @@ -206,7 +207,9 @@ def _run( ) # Get the app module. - prerequisites.get_compiled_app() + if not should_use_granian(): + # Granian fails if the app is already imported. + prerequisites.get_compiled_app() # Warn if schema is not up to date. prerequisites.check_schema_up_to_date() diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 7c0c9953f..3d6233413 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -216,9 +216,6 @@ def run_backend( frontend_present: Whether the frontend is present. """ web_dir = get_web_dir() - # Create a .nocompile file to skip compile for backend. - if web_dir.exists(): - (web_dir / constants.NOCOMPILE_FILE).touch() if not frontend_present: notify_backend() @@ -227,6 +224,9 @@ def run_backend( if should_use_granian(): run_granian_backend(host, port, loglevel) else: + # Create a .nocompile file to skip compile for backend. + if web_dir.exists(): + (web_dir / constants.NOCOMPILE_FILE).touch() run_uvicorn_backend(host, port, loglevel)