The simplest task here would be to add use_reloader=False to your call to app.run - that is: app.run(debug=True, use_reloader=False)
Alternatively, you can check the value of WERKZEUG_RUN_MAIN in the environment:
if os.environ.get("WERKZEUG_RUN_MAIN") == "true":
However, the condition is a bit more complicated if you want the behavior to occur at any time other than the boot process:
if not app.debug or os.environ.get("WERKZEUG_RUN_MAIN") == "true":
Sean Vieira Feb 28 2018-12-12T00: 00Z
source share