vim, git, aws and other three-letter words

Software Development Notes

Debugging Python with ipdb and pdbpp

To get a very convenient full-screen console debugger for Python, install the ipdb and pdbpp packages.

Then use __import__('ipdb').set_trace() to start the debugger and enter sticky to switch to the full-screen mode.

Both packages can be installed with pip:

virtualenv -p python3 venv
source venv/bin/activate

pip install ipdb
pip install pdbpp

Note: the combination of packages is now broken with recent IPython changes. A quick fix is to pin ipython to ipython<9.16.

The ipdb package improves the standard (pdb) debugger by adding syntax highlighting and code completion. And pdbpp adds the sticky mode, so the debugger can be run in full-screen mode in the terminal:

2018-11-28-python-debugging.gif
Figure 1: debugger demo

This way we get an interactive debugging environment where we can execute the code, inspect variables and experiment with the live application state.

It works well for command-line scripts and web applications; the only thing you need is to start the application from the terminal in a non-daemon mode, so the debugger can break the execution and switch to the interactive mode.

It also works if the app is started inside a Docker container (same here: run in foreground mode, docker run ... or docker-compose run ... without the -d flag).

Tags: python