debugging a uwsgi python application using pycharm(使用 pycharm 调试 uwsgi python 应用程序)
问题描述
是否可以使用 PyCharm 之类的 ide 调试 uwsgi 应用程序?我可以通过直接从 pycharm 运行基于烧瓶的应用程序来很好地调试它们,但甚至不能从 pycharm 中运行 uwsgi 应用程序.
我必须使用远程调试吗?是否可以使用 run 从 pycharm 中启动 uwsgi 应用程序?
您仍然可以在 uWSGI 之外运行您的 WSGI 应用程序以进行开发和调试.
但有时这是不可能的,例如,如果您的应用依赖于 uWSGI API 功能.
据我所知,您不能使用 PyCharm 中的附加到进程",因为您的 WSGI 应用程序正在嵌入到 uWSGI 中运行,并且没有可见的 Python 进程.远程调试不过效果很好.
在 PyCharm 发行版中找到
pycharm-debug*.egg 文件.例如,在 OSX 上,两者都可以在/Applications/PyCharm.app/Contents 中找到复制
pycharm-debug-py3k.egg到您的 Flask 应用旁边,如果您使用的是 Python 2.7,则复制pycharm-debug.eggp>在 PyCharm 中,从运行/调试配置"对话框创建Python 远程调试"配置.在此示例中,我使用
localhost和端口4444.此对话框将显示相应的pydevd.settrace(...)行.将以下代码添加到您的应用中:
导入系统sys.path.append('pycharm-debug-py3k.egg') # 替换为 Python 2.7 的 pycharm-debug.egg导入 pydevd# 以下行可以从运行/调试配置"对话框中复制pydevd.settrace('localhost', 端口=4444, stdoutToServer=True, stderrToServer=True)在 PyCharm 中,启动远程调试会话.PyCharm 的控制台应显示以下行:
等待过程连接...像往常一样从 uWSGI 运行你的应用程序.它应该附加到调试器,并且 PyCharm 的控制台应该显示:
连接到 pydev 调试器 (build 139.711)您的应用应该在
pydevd.settrace(...)行中断.然后,您可以像往常一样继续使用 PyCharm 调试器(断点等)
Is it possible to debug a uwsgi application using an ide like PyCharm? I can debug flask based apps fine by running them directly from pycharm but cannot even run a uwsgi app from within pycharm.
Do I have to use remote debugging? Is it possible to start a uwsgi app from within pycharm using run?
You can still run your WSGI app outside of uWSGI for development and debugging purposes.
However sometimes this is not possible, for example if your app relies on uWSGI API features.
As far as I know you can't use "Attach to Process" from PyCharm because your WSGI app is running embedded into uWSGI, and there are no visible Python processes. Remote debugging however works like a charm.
Locate
pycharm-debug*.eggfiles in your PyCharm distribution. For example, on OSX both can be found in/Applications/PyCharm.app/ContentsCopy
pycharm-debug-py3k.eggnext to your Flask app, or copypycharm-debug.egginstead if you are using Python 2.7In PyCharm, create a "Python Remote Debug" configuration from "Run/Debug Configurations" dialog. In this example I use
localhostand port4444. This dialog will show you the correspondingpydevd.settrace(...)line.Add the following code to your app :
import sys sys.path.append('pycharm-debug-py3k.egg') # replace by pycharm-debug.egg for Python 2.7 import pydevd # the following line can be copied from "Run/Debug Configurations" dialog pydevd.settrace('localhost', port=4444, stdoutToServer=True, stderrToServer=True)In PyCharm, start the remote debugging session. PyCharm's console should display the following line :
Waiting for process connection...Run your app from uWSGI as usual. It should attach to the debugger, and PyCharm's console should display :
Connected to pydev debugger (build 139.711)Your app should break on the
pydevd.settrace(...)line. You can then continue and use PyCharm debugger as usual (breakpoints and so on)
这篇关于使用 pycharm 调试 uwsgi python 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 pycharm 调试 uwsgi python 应用程序
基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
