app_module_for_backend.py 743 B

123456789101112131415161718192021222324
  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. # Force background compile errors to print eagerly
  12. ThreadPoolExecutor(max_workers=1).submit(app.compile_).add_done_callback(
  13. lambda f: f.result()
  14. )
  15. # ensure only "app" is exposed.
  16. del app_module
  17. del get_app
  18. del get_compiled_app
  19. del constants
  20. del ThreadPoolExecutor