kortina.nyc / notes
29 Dec 2021 | by kortina

Use ipdb as the default python debugger with breakpoint() and PYTHONBREAKPOINT

I must have googled this in the past before it existed, but it seems kind of like a no-brainer to want all of the ipython bells and whistles when you’re debugging python code at a breakpoint.

Whelp, apparently python 3.7 introduced a convenient way to do this with the PYTHONBREAKPOINT environment variable and the breakpoint() function in PEP 553.

Not only does this allow you to set the default debugger, it also saves a bunch of ugly multi-line code. Previously, I was using this vscode snippet to insert breakpoints that my linter (black) did not complain about:

"black-friendly-python-pdb": {
  "scope": "python",
  "prefix": "bpdb",
  "body": [
    "__import__(\"pdb\").set_trace()  # FIXME",
  ]
},

Yuck.

Now, I have a much cleaner setup (dotfiles diff). In my ~/.profile, I have:

export PYTHONBREAKPOINT="ipdb.set_trace"

I installed ipdb:

pip install ipdb

Et voila!

def foo():
  breakpoint()
  ...

This will enter the ipdb breakpoint with all the ipython niceties.


Tweet Like andrew.kortina@gmail.com