Skip to main content

Remote vanilla PDB (over TCP sockets) done right: no extras, proper handling around connection failures and CI. Based on pdbx.

  • Free software: BSD 2-Clause License

Installation

pip install remote-pdb

Usage

To open a remote PDB on first available port:

from remote_pdb import set_trace
set_trace() # you'll see the port number in the logs

To use some specific host/port:

from remote_pdb import RemotePdb
RemotePdb('127.0.0.1', 4444).set_trace()

To connect just run telnet 127.0.0.1 4444. When you are finished debugging, either exit the debugger, or press Control-], then Control-d.

Alternately, one can connect with NetCat: nc -C 127.0.0.1 4444 or Socat: socat readline tcp:127.0.0.1:4444 (for line editing and history support). When finished debugging, either exit the debugger, or press Control-c.

Note that newer Ubuntu disabled readline support in socat, so if you get unknown device/address "readline" try using rlwrap like this:

rlwrap socat - tcp:127.0.0.1:4444

Using in containers

If you want to connect from the host to remote-pdb running inside the container you should make sure that:

  • The port you will use is mapped (eg: -p 4444:4444).

  • The host is set to 0.0.0.0 (localhost` or ``127.0.0.1 will not work because Docker doesn’t map the port on the local interface).

Integration with breakpoint() in Python 3.7+

If you are using Python 3.7 one can use the new breakpoint() built in to invoke remote PDB. In this case the following environment variable must be set:

PYTHONBREAKPOINT=remote_pdb.set_trace

The debugger can then be invoked as follows, without any imports:

breakpoint()

As the breakpoint() function does not take any arguments, environment variables can be used to specify the host and port that the server should listen to. For example, to run script.py in such a way as to make telnet 127.0.0.1 4444 the correct way of connecting, one would run:

PYTHONBREAKPOINT=remote_pdb.set_trace REMOTE_PDB_HOST=127.0.0.1 REMOTE_PDB_PORT=4444 python script.py

If REMOTE_PDB_HOST is omitted then a default value of 127.0.0.1 will be used. If REMOTE_PDB_PORT is omitted then the first available port will be used. The connection information will be logged to the console, as with calls to remote_pdb.set_trace().

To quiet the output, set REMOTE_PDB_QUIET=1, this will prevent RemotePdb from producing any output – you’ll probably want to specify REMOTE_PDB_PORT as well since the randomized port won’t be printed.

Note about OS X

In certain scenarios (backgrounded processes) OS X will prevent readline to be imported (and readline is a dependency of pdb). A workaround (run this early):

import signal
signal.signal(signal.SIGTTOU, signal.SIG_IGN)

See #9 and cpython#14892.

Requirements

Python 2.6, 2.7, 3.2, 3.3 and PyPy are supported.

Similar projects

Changelog

2.1.0 (2020-07-24)

  • Changed logging to use remote_pdb logger instead of the root one. Contributed by Terence Honles in #24.

2.0.0 (2019-07-31)

  • Fixed inconsistency with normal use of pdb - BdbQuit will now be raised on quitting. Contributed by Anthony Sottile in #18. BACKWARDS INCOMPATIBLE.

  • Added REMOTE_PDB_QUIET=1 to silence output. Contributed by Anthony Sottile in #19.

1.3.0 (2019-03-13)

  • Documented support for Python 3.7’s breakpoint().

  • Added support for setting the socket listening host/port through the REMOTE_PDB_HOST/REMOTE_PDB_PORT environment variables. Contributed by Matthew Wilkes in #14.

  • Removed use of rw file wrappers around sockets (turns out socket’s makefile is very buggy in Python 3.6 and later - output is discarded). Contributed in #13.

1.2.0 (2015-09-26)

  • Always print/log listening address.

1.1.3 (2015-07-06)

  • Corrected the default frame tracing starts from.

1.1.2 (2015-07-06)

  • Small readme update.

1.1.1 (2015-07-06)

  • Remove bogus remote_pdb console script.

1.1.0 (2015-06-21)

  • Fixed buffering issues when running on Python 3 and Windows.

1.0.0 (2015-06-15)

  • Added support for PDB++.

0.2.1 (2014-03-07)

  • First release on PyPI.

Release files for remote-pdb 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for remote-pdb 2.1.0
File Size Uploaded
remote-pdb-2.1.0.tar.gz 22.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for remote-pdb 2.1.0
File Interpreter ABI Platform
remote_pdb-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.6 kB

Release files / remote-pdb-2.1.0.tar.gz

Download URL remote-pdb-2.1.0.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2d70c6f41e0eabf0165e8f1be58f82aa7a605aaeab8f2aefeb9ce246431091c1
BLAKE2b-256 checksum
How to use checksums
e4b54944cac06fd9fc4a2e168313ec220aa25ed96ce83947b63eea5b4045b22d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

Release files / remote_pdb-2.1.0-py2.py3-none-any.whl

Download URL remote_pdb-2.1.0-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
94f73a92ac1248cf16189211011f97096bdada8a7baac8c79372663bbb57b5d0
BLAKE2b-256 checksum
How to use checksums
71c5d208c66344bb785d800adb61aef512290d3473052b9e7697890f0547aff2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

1 release file

1.1.1

1 release file

1.1.0

2 release files

1.0.0

2 release files

0.2.1

1 release file

0.2.0

1 release file

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page