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

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

问题描述

是否可以使用PyCharm之类的工具调试uwsgi应用程序?我可以通过直接从pycharm运行基于烧瓶的应用程序来进行调试,但不能甚至在pycharm中运行uwsgi应用程序。

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?

推荐答案

您仍然可以在uWSGI外部运行WSGI应用程序,以便运行pycharm中的uwsgi应用程序。开发和调试目的。

You can still run your WSGI app outside of uWSGI for development and debugging purposes.

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

However sometimes this is not possible, for example if your app relies on uWSGI API features.

据我所知,您不能使用PyCharm的附加到进程,因为您的WSGI应用程序正在嵌入到uWSGI中运行,并且没有可见的Python进程。 远程调试然而却很吸引人。

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. 在PyCharm发行版中找到 pycharm-debug * .egg 文件。例如,在OSX上,都可以在 /Applications/PyCharm.app/Contents

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

Copy中找到 pycharm-debug-py3k.egg 放在Flask应用程序旁边,或者如果您是,则复制 pycharm-debug.egg 使用Python 2.7

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

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

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.

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

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)


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

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

    Waiting for process connection...
    


  • 照常从uWSGI运行您的应用程序。它应该附加到调试器,并且PyCharm的控制台应该显示:

  • 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)
    


  • 您的应用应该在 pydevd.settrace(...)行。然后,您可以像往常一样继续使用PyCharm调试器(断点等)

  • 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天全站免登陆