Remote-pdb provides a robust, vanilla PDB (Python Debugger) interface over TCP sockets, designed for remote debugging scenarios. It handles connection failures and integrates well with CI environments. The current version is 2.1.0, and releases occur infrequently but with critical fixes and Python version support.
pip install remote-pdbVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up a remote PDB session that listens on a specified host and port. The `set_trace()` call will block execution until a `telnet` client connects. For Python 3.7+, you can also use the built-in `breakpoint()` by setting the `PYTHONBREAKPOINT=remote_pdb.set_trace` environment variable, along with `REMOTE_PDB_HOST` and `REMOTE_PDB_PORT` for configuration.
Before exiting the client (e.g., via Ctrl-C, `exit`, or `quit` commands), ensure you send a `c` (continue) command within the debugger to cleanly disconnect.
Set the host to `0.0.0.0` in your code or via `REMOTE_PDB_HOST` environment variable, and configure Docker port mapping. Example: `REMOTE_PDB_HOST=0.0.0.0 python script.py` and `docker run -p 4444:4444 my_image`
Ensure that `set_trace()` is called in a controlled manner, ideally only by the specific thread/process you intend to debug, or implement a mechanism to serialize debugger access for multi-threaded/multi-process applications.
Be aware that program execution will pause indefinitely at the `set_trace()` call until a telnet or similar client connects. This is by design, but can be a 'gotcha' if not expected.
When `REMOTE_PDB_QUIET=1` is set, you must also explicitly set `REMOTE_PDB_PORT` via an environment variable or `RemotePdb` constructor to know which port to connect to.
Install the package using pip: 'pip install remote-pdb'.
Ensure the module is installed with 'pip install remote-pdb' and use the correct import: 'from remote_pdb import RemotePdb'.
Verify that the remote-pdb server is running and listening on the correct host and port, and that the network allows connections.
Before exiting the client, send a 'c' (continue) command within the debugger to cleanly disconnect.
Choose a different port or ensure that the port is free before starting remote-pdb.