使用 pycharm 调试 uwsgi python 应用程序 [英] debugging a uwsgi python application using pycharm

查看:39
本文介绍了使用 pycharm 调试 uwsgi python 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 PyCharm 之类的 ide 调试 uwsgi 应用程序?我可以通过直接从 pycharm 运行基于烧瓶的应用程序来很好地调试它们,但甚至不能从 pycharm 中运行 uwsgi 应用程序.

我必须使用远程调试吗?是否可以使用 run 从 pycharm 中启动 uwsgi 应用程序?

解决方案

您仍然可以在 uWSGI 之外运行您的 WSGI 应用程序以进行开发和调试.

但有时这是不可能的,例如,如果您的应用依赖于 uWSGI API 功能.

据我所知,您不能使用 PyCharm 中的附加到进程",因为您的 WSGI 应用程序正在嵌入到 uWSGI 中运行,并且没有可见的 Python 进程.远程调试不过效果很好.

  1. 在 PyCharm 发行版中找到 pycharm-debug*.egg 文件.例如,在 OSX 上,两者都可以在 /Applications/PyCharm.app/Contents

  2. 中找到
  3. 复制 pycharm-debug-py3k.egg 到您的 Flask 应用旁边,如果您使用的是 Python 2.7,则复制 pycharm-debug.eggp>

  4. 在 PyCharm 中,从运行/调试配置"对话框创建Python 远程调试"配置.在此示例中,我使用 localhost 和端口 4444.此对话框将显示相应的 pydevd.settrace(...) 行.

  5. 将以下代码添加到您的应用中:

    导入系统sys.path.append('pycharm-debug-py3k.egg') # 替换为 Python 2.7 的 pycharm-debug.egg导入 pydevd# 以下行可以从运行/调试配置"对话框中复制pydevd.settrace('localhost', 端口=4444, stdoutToServer=True, stderrToServer=True)

  6. 在 PyCharm 中,启动远程调试会话.PyCharm 的控制台应显示以下行:

    等待过程连接...

  7. 像往常一样从 uWSGI 运行你的应用程序.它应该附加到调试器,并且 PyCharm 的控制台应该显示:

    连接到 pydev 调试器 (build 139.711)

  8. 您的应用应该在 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.

  1. Locate pycharm-debug*.egg files in your PyCharm distribution. For example, on OSX both can be found in /Applications/PyCharm.app/Contents

  2. Copy pycharm-debug-py3k.egg next to your Flask app, or copy pycharm-debug.egg instead if you are using Python 2.7

  3. In PyCharm, create a "Python Remote Debug" configuration from "Run/Debug Configurations" dialog. In this example I use localhost and port 4444. This dialog will show you the corresponding pydevd.settrace(...) line.

  4. 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)
    

  5. In PyCharm, start the remote debugging session. PyCharm's console should display the following line :

    Waiting for process connection...
    

  6. 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)
    

  7. 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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆