我正在尝试从IPython运行我的烧瓶应用程序。但是,如果出现SystemExit
错误,则会失败。
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
使用IPython运行此操作将显示以下错误:
SystemExit Traceback (most recent call last)
<ipython-input-35-bfd7690b11d8> in <module>()
17
18 if __name__ == '__main__':
---> 19 app.run(debug = True)
/Users/ravinderbhatia/anaconda/lib/python2.7/site-packages/flask/app.pyc in run(self, host, port, debug, **options)
770 options.setdefault('use_debugger', self.debug)
771 try:
--> 772 run_simple(host, port, self, **options)
773 finally:
774 # reset the first request information if the development server
/Users/ravinderbhatia/anaconda/lib/python2.7/site-packages/werkzeug/serving.py in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
687 from ._reloader import run_with_reloader
688 run_with_reloader(inner, extra_files, reloader_interval,
--> 689 reloader_type)
690 else:
691 inner()
/Users/ravinderbhatia/anaconda/lib/python2.7/site-packages/werkzeug/_reloader.py in run_with_reloader(main_func, extra_files, interval, reloader_type)
248 reloader.run()
249 else:
--> 250 sys.exit(reloader.restart_with_reloader())
251 except KeyboardInterrupt:
252 pass
SystemExit: 1
发布于 2018-03-23 18:52:34
您正在使用朱庇特笔记本或IPython运行开发服务器。您还启用了调试模式,这在默认情况下启用了重新加载器。重新加载程序尝试重新启动进程,IPython无法处理该进程。
最好使用flask
命令来运行开发服务器。
export FLASK_APP=my_app.py
export FLASK_DEBUG=1
flask run
或者使用普通的python
解释器来运行应用程序,如果您仍然希望使用app.run
,则不再推荐使用app.run
。
python my_app.py
或者,如果您想从木星调用app.run
,则禁用重新加载程序。
app.run(debug=True, use_reloader=False)
在Visual代码中,若要在启动程序(而不是启动python)中设置flask run
,请在..vscode/unch.json中使用此配置
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": { "FLASK_APP": "my_app.py", "FLASK_ENV": "development" },
"args": ["run"],
"args_": ["run", "--no-debugger"],
"jinja": true
}
发布于 2020-06-23 11:31:59
用这个,它对我来说很好:
app.run(debug=True,use_reloader=False)
发布于 2020-07-17 03:27:03
我也遇到了同样的问题,通过删除debug=True
解决了这个问题。这是我的密码
from flask import Flask
app=Flask(__name__)
@app.route('/')
def home():
return "Homepage Here"
if __name__=="__main__":
app.run()
https://stackoverflow.com/questions/49456385
复制相似问题