在这里要做的最简单的事情就是将
use_reloader=False你的呼叫添加到
app.run-即:
app.run(debug=True, use_reloader=False)
或者,你可以检查
WERKZEUG_RUN_MAIN环境中的值:
if os.environ.get("WERKZEUG_RUN_MAIN") == "true": # The reloader has already run - do what you want to do here但是,当你希望行为在加载过程中以外的任何时间发生时,情况会更加复杂:
if not app.debug or os.environ.get("WERKZEUG_RUN_MAIN") == "true": # The app is not in debug mode or we are in the reloaded process


