reflex/reflex/app_module_for_backend.py
jackie-pc a4c8c72177
(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
2024-02-08 12:13:39 -08:00

22 lines
646 B
Python

"""Shims the real reflex app module for running backend server (uvicorn or gunicorn).
Only the app attribute is explicitly exposed.
"""
from concurrent.futures import ThreadPoolExecutor
from reflex import constants
from reflex.utils.prerequisites import get_app, get_compiled_app
if "app" != constants.CompileVars.APP:
raise AssertionError("unexpected variable name for '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.
del app_module
del get_app
del get_compiled_app
del constants
del ThreadPoolExecutor