0

I want to execute a function before my flask app starts and this is what I did for achieving my goal.

# flask_app.py

def dummy_func():
    print('some dummy text')

def create_app() -> Flask:
    app = Flask(__name__)
    # doing somethings
    dummy_func()
    return app

if __name__ == '__main__':
    app = create_app()
    app.run()

With this example, everything works fine but it calls dummy_func() two times and I don't want this to happen.

# flask run
 * Serving Flask app 'run' (lazy loading)
 * Environment: development
 * Debug mode: on
some dummy text
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 136-570-428
some dummy text

And my question is why it has happened and how can I fix that?

0 Answers0