app.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import sys
  3. def is_db_command():
  4. if len(sys.argv) > 1 and sys.argv[0].endswith("flask") and sys.argv[1] == "db":
  5. return True
  6. return False
  7. # create app
  8. if is_db_command():
  9. from app_factory import create_migrations_app
  10. app = create_migrations_app()
  11. else:
  12. # It seems that JetBrains Python debugger does not work well with gevent,
  13. # so we need to disable gevent in debug mode.
  14. # If you are using debugpy and set GEVENT_SUPPORT=True, you can debug with gevent.
  15. if (flask_debug := os.environ.get("FLASK_DEBUG", "0")) and flask_debug.lower() in {"false", "0", "no"}:
  16. from gevent import monkey # type: ignore
  17. # gevent
  18. monkey.patch_all()
  19. from grpc.experimental import gevent as grpc_gevent # type: ignore
  20. # grpc gevent
  21. grpc_gevent.init_gevent()
  22. import psycogreen.gevent # type: ignore
  23. psycogreen.gevent.patch_psycopg()
  24. from app_factory import create_app
  25. app = create_app()
  26. celery = app.extensions["celery"]
  27. if __name__ == "__main__":
  28. app.run(host="0.0.0.0", port=5001)