I have a small flask application which needs some configuration. If something is missing I'd like to "abort" startup so the error will be noticed immediately.
My WSGI script is trivial but maybe it helps to understand my question:
from myapp.startup import init_app
app = init_app()
So say somewhere in ìnit_app()
the code finds that something is wrong (e.g. missing configuration values or outdated DB schema version, insecure directory permissions, ...) I'd like to ensure that the application is not run (because it will fail later anyway).
I can throw in a sys.exit(1)
somewhere in the code but then flask retries endlessly to start the app (user does not see any page). Of course I could build an alternate WSGI app which shows some text.
But I hoped there would be some kind of "best practice" (and ideally existing Python code so it even looks "nice").
- Is there a way to tell flask/the WSGI server that the app startup failed and it should not try again?
- Is there existing code to handle "setup errors"?