PDB Attach

3.0.1 · active · verified Wed Apr 15

pdb-attach is a Python debugger extension that allows users to attach to already running Python processes. Unlike standard `pdb.set_trace()`, it facilitates debugging long-running or unresponsive applications by enabling remote connection. It's currently at version 3.0.1 and appears to be actively maintained, with a focus on POSIX-compliant operating systems.

Warnings

Install

Imports

Quickstart

To use `pdb-attach`, the target Python program must first be modified to call `pdb_attach.listen()` at the desired point where debugging should be enabled. This function sets up a listening socket. Then, from a separate terminal, the `pdb_attach` command-line tool is used with the target process's PID and the specified port to initiate a debugging session.

import pdb_attach
import time
import os

def my_long_running_function():
    print(f"Process PID: {os.getpid()}")
    print("Starting long-running function...")
    pdb_attach.listen(port=5555)
    print("pdb_attach is listening on port 5555. Attach with: pdb_attach PID 5555")
    for i in range(100):
        # Simulate work
        time.sleep(1)
        if i % 10 == 0:
            print(f"Iteration {i}")
    print("Function finished.")

if __name__ == "__main__":
    my_long_running_function()

view raw JSON →