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 https://github.com/fabioz/PyDev.Debugger 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.
See you next week,
Subscribe to Blog updates
Thanks, we've got you!
Five Things To Love About the New UI
Are you using the New UI yet? Not yet? Let me tell you why it's the best thing since sliced bread! Let’s get it enabled and take a look around. The easiest way to do that is from the Settings cog at the top-right of the UI: PyCharm will need to restart, but that’s it; you’re done! In t…
Tutorial: Visual testing with pytest
If you are like many Python developers out there you LOVE writing code! Tests? Not so much. Whether it’s the concept of testing or the interface of testing tools, testing is a chasm not all developers cross. The Visual Testing with pytest tutorial aims to bring Python testing to the masses, tak…
Smart execution of R code
R plugin is announcing some helpful features to track execution of your R code: 1. Execute your R file as a runnable process, job. Jobs are shown in a separate tab in the R console. You can preview the job status (succeeded or failed), the duration of the execution, and the time you launched the …
New Database Features in PyCharm 2020.1
PyCharm 2020.1 comes with new Database export features that make exporting data easier. You can now see previews of the data that you want to export, letting you have a quick glance of what the data will look like. Furthermore, as many of our users prefer to export to Excel files, we've also adde…