Home

Oct. 29, 2018, 3 min read

Python Remote Debuggers

IDEs like PyCharm or Eclipse with Pydev often praise themselves with their advanced debugging features, allowing you to set breakpoint directly in code to then pause and interact with the live application.

There are a number of standalone debugging tools that allow you to enjoy this workflow without having to use a specific IDE. Most of them are based on the builtin pdb module, some extend it with UI to display the current stack frame and debug in a more convenient way.

Here is a small list of tools with a few notes about why they may be useful to you. With a little bit of extra work you could even use them for "real remote" debugging outside of your local network.


Note: Once installed, you need to make sure that the code you are setting your breakpoint in has access to that installed package.

If the code uses the same python environment (e.g. virtualenv) that you installed into, it's all good. If not, you may have to revert to small hacks like

import sys; sys.path.append("/path/to/installed/package/parent/directory")

# Import library and add breakpoint below ...

Ugly, but works. Can be put into a snippet in your text editor of choice to ease usage.

python-remote-pdb

This allows to connec to a pdb session over a TCP socket. No GUI, just the good old pdb shell.

Installation

$ pip install python-remote-db

Usage in Code

from remote_pdb import set_trace; set_trace()

# Specifying the Port

from remote_pdb import RemotePdb

RemotePdb("127.0.0.1", 5678).set_trace()

Usage from Outside

# Use one of the following, whatever works best for you

$ telnet 127.0.0.1 5678

$ nc -C 127.0.0.1 5678

$ socat readline tcp:127.0.0.1:5678

python-web-pdb

Once a breakpoint is reached this runs a small web application to show a nice minimal GUI to interact with.

Installation

$ pip install web-pdb

Usage in Code

# Adding a breakpoint

import web_pdb; web_pdb.set_trace()

# Specifying the Port

import web_pdb; web_pdb.set_trace(5678)

Usage from Outside

Visit URL in Browser: http://localhost:5678

winpdb

This used to be a great GUI based on wxPython that ran standalone on your machine. However it seems mostly unmaintained and its efforts to port to Python 3 have come to a halt (for now).

Therefore and because installing that old wxPython 3.x version that is used can be a big pain I cannot recommend it any longer.

debugging_cup