PyCharm集成调试器会降低应用程序的速度

时间:2022-04-07 20:44:40

I am using PyCharm to debug a moderately complex Pyramid web application with a lot of dependencies. When I run the application inside PyCharm using PyCharm's Debug run, the application start up slows down significantly. This kills the normal web application workflow of edit, save, refresh. The slowdown is significant, making the application restart to take tens of seconds instead of fractions of seconds.

我正在使用PyCharm来调试具有大量依赖性的中等复杂的Pyramid Web应用程序。当我使用PyCharm的Debug运行在PyCharm中运行应用程序时,应用程序启动显着减慢。这会破坏正常的Web应用程序工作流程,即编辑,保存,刷新。减速很重要,使应用程序重新启动需要几十秒而不是几分之一秒。

Is there a way to speed up PyCharm debug runs any way? The similar slowdown would not occur if one is using hardcoded import pdb ; pdb.set_trace() style breakpoints and normal Run mode.

有没有办法以任何方式加速PyCharm调试运行?如果使用硬编码导入pdb,则不会发生类似的减速; pdb.set_trace()样式断点和正常运行模式。

1 个解决方案

#1


The way to get fast debugging sessions in PyCharm (Professional edition) is to use remote debugging, similar to pdb.set_trace().

在PyCharm(专业版)中获得快速调试会话的方法是使用远程调试,类似于pdb.set_trace()。

In the Run/Debug Configurations dialogue, create a Remote Debug configuration. The dialogue contains the instructions, which I will repeat here completeness sake:

在“运行/调试配置”对话框中,创建“远程调试”配置。对话包含说明,我将在此重复完整性:

  1. Add pycharm-debug.egg from the PyCharm installation to the Python path.

    将pycharm-debug.egg从PyCharm安装添加到Python路径。

  2. Add the following import statement:

    添加以下import语句:

    import pydev

  3. Add the following command to connect to the debug server:

    添加以下命令以连接到调试服务器:

    pydevd.settrace('localhost', port=$SERVER_PORT, stdoutToServer=True, stderrToServer=True)

    pydevd.settrace('localhost',port = $ SERVER_PORT,stdoutToServer = True,stderrToServer = True)

These strings can be copied from the dialogue and pasted into the source. When you choose the host and server port in the dialogue, the pasteable strings will update themselves. Of course, they can also be concatenated to a oneliner using ;.

可以从对话框中复制这些字符串并粘贴到源中。在对话框中选择主机和服务器端口时,可粘贴字符串将自行更新。当然,它们也可以使用;连接到oneliner。

After the settrace() method has been run, the breakpoints you have set in PyCharm will become active.

运行settrace()方法后,您在PyCharm中设置的断点将变为活动状态。

So, where's the file pycharm-debug.egg? Somewhere in the near vicinity of the PyCharm binary. In OS X, you will find the file within the Contents/debug-eggs directory within PyCharm.app. I assume other PyCharm distributions have a similar directory.

那么,文件pycharm-debug.egg在哪里?在PyCharm二进制附近的某处。在OS X中,您将在PyCharm.app中的Contents / debug-eggs目录中找到该文件。我假设其他PyCharm发行版有一个类似的目录。

If you're running the application using a virtualenv, install the egg using easy_install.

如果您使用virtualenv运行应用程序,请使用easy_install安装egg。

If you prefer to run your application within PyCharm (stdout in the PyCharm console is useful), then add the path to the egg file to the Project Interpreter's file paths.

如果您更喜欢在PyCharm中运行应用程序(PyCharm控制台中的stdout很有用),那么将egg文件的路径添加到Project Interpreter的文件路径中。

#1


The way to get fast debugging sessions in PyCharm (Professional edition) is to use remote debugging, similar to pdb.set_trace().

在PyCharm(专业版)中获得快速调试会话的方法是使用远程调试,类似于pdb.set_trace()。

In the Run/Debug Configurations dialogue, create a Remote Debug configuration. The dialogue contains the instructions, which I will repeat here completeness sake:

在“运行/调试配置”对话框中,创建“远程调试”配置。对话包含说明,我将在此重复完整性:

  1. Add pycharm-debug.egg from the PyCharm installation to the Python path.

    将pycharm-debug.egg从PyCharm安装添加到Python路径。

  2. Add the following import statement:

    添加以下import语句:

    import pydev

  3. Add the following command to connect to the debug server:

    添加以下命令以连接到调试服务器:

    pydevd.settrace('localhost', port=$SERVER_PORT, stdoutToServer=True, stderrToServer=True)

    pydevd.settrace('localhost',port = $ SERVER_PORT,stdoutToServer = True,stderrToServer = True)

These strings can be copied from the dialogue and pasted into the source. When you choose the host and server port in the dialogue, the pasteable strings will update themselves. Of course, they can also be concatenated to a oneliner using ;.

可以从对话框中复制这些字符串并粘贴到源中。在对话框中选择主机和服务器端口时,可粘贴字符串将自行更新。当然,它们也可以使用;连接到oneliner。

After the settrace() method has been run, the breakpoints you have set in PyCharm will become active.

运行settrace()方法后,您在PyCharm中设置的断点将变为活动状态。

So, where's the file pycharm-debug.egg? Somewhere in the near vicinity of the PyCharm binary. In OS X, you will find the file within the Contents/debug-eggs directory within PyCharm.app. I assume other PyCharm distributions have a similar directory.

那么,文件pycharm-debug.egg在哪里?在PyCharm二进制附近的某处。在OS X中,您将在PyCharm.app中的Contents / debug-eggs目录中找到该文件。我假设其他PyCharm发行版有一个类似的目录。

If you're running the application using a virtualenv, install the egg using easy_install.

如果您使用virtualenv运行应用程序,请使用easy_install安装egg。

If you prefer to run your application within PyCharm (stdout in the PyCharm console is useful), then add the path to the egg file to the Project Interpreter's file paths.

如果您更喜欢在PyCharm中运行应用程序(PyCharm控制台中的stdout很有用),那么将egg文件的路径添加到Project Interpreter的文件路径中。