Mat*_*att 20 python pycharm flask
我正在使用Pycharm 4,烧瓶0.10.1,python 3.4
似乎从pycharm内部运行一个烧瓶应用程序,如果我运行它:
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
我的断点被忽略了.经过一些谷歌搜索,我发现为了让PyCharm停在断点上,我应该运行烧瓶:
app.run(debug=True, use_reloader=False)
Run Code Online (Sandbox Code Playgroud)
现在PyCharm在断点上正确停止,但我错过了自动加载功能.
有没有办法让两者一起工作?
使用python 2.7这两件事都有效
我向PyCharm报告了这个问题:https://youtrack.jetbrains.com/issue/PY-13976
Mig*_*uel 20
我将从简短的回答开始:不,你想要的任何版本的PyCharm都不能用到4.0.1.
问题是,当您使用重新加载器时,Flask应用程序在子进程中运行,因此PyCharm调试器将附加到主进程并且无法控制子进程.
在我看来,解决这个问题的最好方法是让Jetbrains在他们的IDE中构建一个"重启更改"功能.然后你根本不需要使用Werkzeug的重新加载器,你可以直接从PyCharm获得相同的功能.
直到Jetbrains决定实施这个,我可以分享我的解决方法,这不是非常糟糕.
我同意它并不完美,但是一旦Ctrl-D进入你的肌肉记忆,你甚至都不会想到它.
祝好运!
问题是因为use_reloader=Truewerkzeug 应用程序是在主应用程序的单独(子)线程中启动的,而 PyCharm 无法正确处理断点,因为断点在线程启动时丢失。
您可以尝试遵循此线程:http://forum.jetbrains.com/thread/PyCharm-776,但似乎没有太多进展。
我建议使用类似 Python 的东西pdb,即:
@app.route('/<string:page>')
def main(page):
import pdb; pdb.set_trace() # This line actually stops application execution
# and starts Python debug shell in the console
# where you can examine current scope and continue
# normal code execution at any time.
# You can inject *any* code here.
# For example, if you type `print page` during pause,
# it will output content of "page" variable.
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7184 次 |
| 最近记录: |