10 Comments

Great article. pdb is one of those tools which has a pretty large ROI payoff and everyone should learn to use. One point I feel should be mentioned (and the main reason I switched to using the PyCharm debugger) is that pdb doesn't support debugging multithreaded programs very well (See https://github.com/python/cpython/issues/85743, https://github.com/python/cpython/issues/67352 and https://github.com/python/cpython/issues/65480)

Expand full comment

Indeed. Also, remote debugging is not possible with pdb.

Expand full comment

Loving this post. I use pdb because I’m debugging code that executes within a docker container and docker compose. I use breakpoint(), step, continue, next, and list quite a bit. Jump, until, and display are new to me though. Does display stop and show a value whenever a value changes, even if you’re next-ing over a function call?

Expand full comment

I am seeing ipdb in our env too so will give that a try.

Expand full comment

yes but if you change scope, it will display an error

Expand full comment

If you like pdb making the jump to PyCharm will payoff huge.

Some advantages:

The breakpoints aren't part of the code

You can group them and toggle them off and on

When a break point hits you can jump up the stack which will take you to that code and also give you access to the context at that point

Conditional breakpoints

You have a console just like pdb and can execute code.

Expand full comment

Indeed, PyCharm (and VScode) have a very good Python support, and you can leverage that in their debugger, which is very useful.

I can't assume the reader have one particular editor or skill level though, so this article covers the need for a good chunk of the python user base. And once you know how to use pdb, it's easy to jump into PyCharm and use its excellent debugger.

Expand full comment

Very true. The article is a good intro to pdb. Thanks

Expand full comment

Awesome guide! I blindly use ipdb with a small subset of all these commands. I'd be curious to hear your thoughts on the benefits vs vanilla pdb.

Expand full comment

I only use vanilla pdb when I can't use ipdb, the ipdb experience is way more comfy. The main advantage of pdb is that it's always there.

But I'm writing this blog to help the largest number of people, and this means I want people that are not experienced with programming to be able to debug as well. In this case, pdb is the best option since you don't know what environment they are in, what editor they use, what are their skill level, etc.

It's also very important that I start the first months with articles establishing the basics in a way that satisfy my desire for quality. This way I will be able to reference this work in future articles every time I have a post with prerequisite knowledge so people that don't know what I'm talking about can read them and come back. Unfortunately I can't do that with other source because very few are good enough, cover enough topics, and are guaranteed to be still online in a few years.

Expand full comment