Pycharm logo

The PyCharm Blog

The Python IDE for Professional Developers

Features Tips & Tricks

Feature Spotlight: Python Debugger and ‘Attach to Process’

Happy Friday everyone,

Today I’d like to highlight some recent changes and improvements in PyCharm`s Python debugger and explore the brand new attach to process in more detail.

Previously PyCharm used a special fork of the PyDev debugger with some PyCharm-specific changes, as well as our own unique features like GEvent debugging and breakpoints at Django templates. Before releasing PyCharm 4, we decided to contribute to open-sourced software and merged our debugger code with that from the original PyDev repository. Now the work on the debugger continues from both sides (PyCharm and PyDev) in one place. The merged source code now lives at and pull requests are greatly appreciated!

As a result of the unification and the work done since PyCharm 3.4, the debugger in PyCharm 4 has grown more powerful. We’ve added the Referring Objects view, Jinja 2 templates debugging, and other small improvements. Still, the most notable debugger feature introduced in PyCharm 4 is attach to process.

Using this feature you can connect the PyCharm debugger with any running Python process and debug in the attached mode.

Note: ‘Attach to Process’ functionality is available in both PyCharm Community Edition and PyCharm Professional Edition starting with v4.0. This feature is supported on all Windows, Linux and Mac platforms.

Let me show you how it works.

Say we have some long running application that we want attach to. In my example I’ll use a simple graphical Minecraft-inspired application that I found on GitHub.

I have opened the project in PyCharm and launched it using standard run/debug configurations:


The project is running, so now I can attach the debugger to it. For that I go to Tools and select Attach to Process. PyCharm shows the list of running Python processes in our system. I select the Minecraft process and click OK:


PyCharm automatically shows the debugger console with the message that the debugger has successfully connected to the process:


From this point on, debugger works in the attached mode. Let’s make use of it and stop at some line of code. To do that, in the editor I put a breakpoint on the line with some reachable code. In my example I’ve put the breakpoint on the line containing the definition of the cube_vertices function, which is being called a lot. In a few seconds, once the process reaches the breakpoint, PyCharm will stop at the breakpoint and show us the debugger with frames, variables and watches views:


Now we can use the debugger as usual – stepping into/over, pausing and resuming the process, evaluating variables and expressions, and changing the runtime context:


That’s it! Hopefully you’ll appreciate this addition to the new joint-effort PyCharm debugger, along with other handy features introduced in the latest version of PyCharm.

And if you’re craving for yet more details on PyCharm debugger, see this tutorial or the online help.

See you next week,

Comments below can no longer be edited.

21 Responses to Feature Spotlight: Python Debugger and ‘Attach to Process’

  1. Avatar

    Peter Shinners says:

    February 6, 2015

    Alas, the Attach to Process requires a gdb version that is newer than what ships on Redhat 6.5. This ships with gdb 7.2, which does not work at all. I can’t find any documentation or information about what version of gdb is actually required.

  2. Avatar

    laike9m says:

    March 6, 2015

    Well done, this is an amazing feature!

  3. Avatar

    sergio says:

    April 9, 2015

    This is really nice. Will this ever be enhanced to work with remote Pythons, like in a Vagrant box?

  4. Avatar

    Nilesh Thali says:

    June 4, 2015

    I’m using IDEA 15 Community Edition with the PyCharm Community Edition plugin. i can’t debug using the “debug” button in the toolbar (throws a NoSuchMethodError), and though i can attach to a process as you mentioned above, reloading the web page doesn’t end up stopping at any breakpoint.
    what am i doing wrong?

  5. Avatar

    PK says:

    July 4, 2015

    I get the following error when I try to attach to a running python process. I am running Ubuntu 14.04, PyCharm Community Edition 4.5.2 and Python 2.7.x.

    Attaching to a process with PID=3863
    /usr/bin/python2.7 /home/pk/Downloads/pycharm-community-4.5.2/helpers/pydev/pydevd_attach_to_process/ –port 45482 –pid 3863
    Attaching with arch: i386:x86-64
    Running: gdb –nw –nh –nx –pid 3863 –batch –eval-command=’set scheduler-locking off’ –eval-command=’set architecture i386:x86-64′ –eval-command=’call dlopen(“/home/pk/Downloads/pycharm-community-4.5.2/helpers/pydev/pydevd_attach_to_process/”, 2)’ –eval-command=’call DoAttach(0, “import sys;sys.path.append(\”/home/pk/Downloads/pycharm-community-4.5.2/helpers/pydev\”);sys.path.append(\”/home/pk/Downloads/pycharm-community-4.5.2/helpers/pydev/pydevd_attach_to_process\”);import attach_script;attach_script.attach(port=45482, host=\”\”);”, 0)’ –command=’/home/pk/Downloads/pycharm-community-4.5.2/helpers/pydev/pydevd_attach_to_process/linux/’
    Running gdb in target process.
    Attaching to a process with PID=3863
    stdout: [Thread debugging using libthread_db enabled]
    Using host libthread_db library “/lib/x86_64-linux-gnu/”.
    0x00007f33406a7d83 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:81
    The target architecture is assumed to be i386:x86-64
    $1 = 47431744
    $2 = 34422944
    $3 = 0

    stderr: 81 ../sysdeps/unix/syscall-template.S: No such file or directory.
    Traceback (most recent call last):
    File “/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/”, line 63, in
    from libstdcxx.v6.printers import register_libstdcxx_printers
    ImportError: No module named ‘libstdcxx’

    Process finished with exit code 0
    Server stopped.

  6. Avatar

    Daniel Ross says:

    October 2, 2015

    Is there any way to initiate such a connection programmatically from the other end? I work on a server application which spawns a hefty number of processes, and it’s very difficult if not impossible to determine which one I need to be connecting to this way. It would be much easier to use something along the lines of the “import pdb; pdb.set_trace()” pattern.

  7. Avatar

    Thomas St. Pierre says:

    April 14, 2016

    Is there any news on attaching to remote python process? Doesn’t look like there’s any activity on

  8. Avatar

    foo says:

    June 10, 2016

    I love this, but if I don’t time the attach just right, I get this

    pthread_cond_wait: Invalid argument
    pthread_cond_wait: Invalid argument
    pthread_cond_wait: Invalid argument
    forever and process hangs

    • Avatar

      sravya says:

      July 27, 2016

      Is is possible to attach debugger to a process running on remote machine

      • Avatar

        Dmitry Filippov says:

        July 27, 2016

        currently this is not possible. However we’re working on it for next releases.

        • Avatar

          Kostas Evaggelidis says:

          May 10, 2018


          Are there any updates on the issue asked?
          Is is possible to attach debugger to a process running on remote machine?

  9. Avatar

    Thomas Ward says:

    February 6, 2017

    Does the debugger autoattach to subprocesses as well? I have a script that executes a `python` subprocess and I’d like to attach there too.

    • Avatar

      Thomas Ward says:

      February 6, 2017

      That is, if I attach it to a local process not started by PyCharm, can it also connect to the subprocesses that are spawned by it?

      • Avatar

        Ernst Haagsman says:

        February 9, 2017

        Unfortunately this is currently not possible, I’ve created a feature request for you: If you’d like to be informed about the progress on this ticket, please sign in on YouTrack and vote for the ticket.

  10. Avatar

    Marcelo de Mattos Nascimento says:

    January 22, 2018

    Can I change the port with Pydev attach to the process?

  11. Avatar

    Nickolas says:

    February 6, 2018

    Is it possible to attach to a C++ program with embedded Python interpreter which is already being debugged (Using CLion)?

  12. Avatar

    Barathi says:

    March 22, 2018

    I have my web py application running

    When I try to attach that process in Pycharm, the application goes down and all I see in the log is lots and lots of this message

    pthread_cond_wait: Invalid argument
    pthread_cond_wait: Invalid argument
    pthread_cond_wait: Invalid argument

    Any help to resolve this is appreciated.

    • Avatar

      Barathi says:

      March 22, 2018

      The debugging thing had been working for quite a few weeks until 2 days back. Recently I upgraded pymongo to 3.6 in my application and after that I saw this (I am not even sure if this is related). But I revered pymongo back to my old version 2.8.1. But still the same issue persists

Discover more