Community编程与开发github.com

Python Debugpy

使用pdb、breakpoint()、事后检查以及debugpy远程附加来调试Python代码。

Python Debugpy 是什么?

Python Debugpy 技能为开发者提供了一套完整的 Python 调试方案,涵盖从简单的本地交互式调试到复杂的远程/无头进程调试。它支持多种调试器入口:`breakpoint()` 适用于本地代码,无需额外启动步骤;`pdb` 模块可用于从头执行脚本、在未捕获异常处停止或进行事后检查;`debugpy` 则专门用于远程或无头环境,允许通过 DAP(调试适配协议)客户端附加到正在运行的进程或新启动的服务。该技能还提供了详细的 pdb 命令参考(包括流程控制、堆栈查看、变量检查、断点设置等),以及一套清晰的使用规则,例如优先使用最小调试重现问题、避免调试器暴露在危险地址、使用唯一端口避免冲突、并在提交前清理调试代码。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/skills/python-debugpy

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Python Debugpy 是做什么的?

当 Python 代码需要交互式调试时使用:隐藏的局部变量、令人困惑的状态变更、失败的测试、子进程、长时间运行的服务,或远程/无头附加。

选择能到达问题帧的最小调试器。

选择

  • breakpoint():本地代码,允许修改源码,最快路径。
  • python3 -m pdb:无需修改源码,从头启动。
  • python3 -m pdb -c continue:在未捕获异常处停止。
  • debugpy:远程/无头进程、DAP 客户端、已运行的 PID,或服务启动竞态。

命令

python3 -m pdb path/to/script.py arg1
python3 -m pdb -c continue path/to/script.py
python3 -c "import debugpy" || python3 -m pip install debugpy
python3 -m debugpy --listen 127.0.0.1:5678 --wait-for-client path/to/script.py
python3 -m debugpy --listen 127.0.0.1:5678 --wait-for-client -m package.module
python3 -m debugpy --listen 127.0.0.1:5678 --pid <pid>

通过修改源码附加:

import debugpy

debugpy.listen(("127.0.0.1", 5678))
debugpy.wait_for_client()
debugpy.breakpoint()

事后检查:

import pdb, sys

try:
    run()
except Exception:
    pdb.post_mortem(sys.exc_info()[2])
    raise

pdb

  • 流程:n、s、r、c、q。
  • 堆栈/源码:w、u、d、a、l、ll。
  • 值:p expr、pp expr、display expr。
  • 断点:b file.py:42、b func、b file.py:42, condition、cl <num>。
  • 修改/求值:!statement;完整 REPL:interact。

规则

  • 先用最小的命令/测试复现问题。
  • 为 pdb 禁用并行测试工作进程;交互式 stdin 通常会在工作池内中断。
  • 将 debugpy 保留在激活的虚拟环境中;除非项目已经需要它,否则不要将其添加为项目依赖。
  • 将调试服务器绑定到 127.0.0.1;除非环境隔离或通过隧道访问,否则不要暴露 0.0.0.0。
  • 为并行会话使用唯一的端口。
  • debugpy --pid 会注入到正在运行的进程中;附加前确认目标 PID。
  • 如果在 Linux 上 PID 附加失败,先检查 ptrace/容器权限,再修改目标。
  • 提交前清理:rg -n 'breakpoint\(|pdb\.set_trace|debugpy\.' --type py。
  • 在无调试器的情况下重新运行正常的项目测试/门禁。
  • PYTHONBREAKPOINT=0 可禁用 breakpoint()。
  • 如果进程在调试器分离后卡住,请确认它没有停在断点处。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills when explicitly requested; install, verify, update, uninstall, publish, or sync skills.

相关技能