Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm integrated debugger slows down application

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.

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.

like image 472
Mikko Ohtamaa Avatar asked Oct 20 '22 12:10

Mikko Ohtamaa


1 Answers

The way to get fast debugging sessions in PyCharm (Professional edition) is to use remote debugging, similar to 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.

  2. Add the following import statement:

    import pydev

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

    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 ;.

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

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.

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

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.

like image 136
Dag Høidahl Avatar answered Oct 24 '22 02:10

Dag Høidahl