app_module_for_backend.py 646 B

123456789101112131415161718192021
  1. """Shims the real reflex app module for running backend server (uvicorn or gunicorn).
  2. Only the app attribute is explicitly exposed.
  3. """
  4. from concurrent.futures import ThreadPoolExecutor
  5. from reflex import constants
  6. from reflex.utils.prerequisites import get_app, get_compiled_app
  7. if "app" != constants.CompileVars.APP:
  8. raise AssertionError("unexpected variable name for 'app'")
  9. app_module = get_app(reload=False)
  10. app = getattr(app_module, constants.CompileVars.APP)
  11. ThreadPoolExecutor(max_workers=1).submit(app.compile_)
  12. # ensure only "app" is exposed.
  13. del app_module
  14. del get_app
  15. del get_compiled_app
  16. del constants
  17. del ThreadPoolExecutor