python-debugpy
它能做什么
它指导 AI 智能体使用 pdb 和 debugpy 等 Python 调试工具,暂停代码并检查其状态。它适合需要在 Python 代码或服务中找出难以理解的错误的开发者。
适用场景
- ✓Python 脚本行为怪异,你需要查看某一点的变量值的时候。
- ✓某个 Python 测试失败,你想逐步检查它的时候。
- ✓需要从远程将调试器附加到长时间运行的 Python 服务的时候。
技能链接
https://github.com/openclaw/openclaw/blob/main/skills/python-debugpy/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Python 脚本算出的数字不对。请帮我在正确的位置暂停,并显示变量的值。”
每周 5 个新技能,1 分钟读完。
工作原理
技能会选择能够定位问题的最小调试器,例如 pdb 会话,或代码中的断点。然后它逐步执行程序、检查变量值,并提出修复建议。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Python Debugpy
Use when Python code needs interactive debugging: hidden locals, confusing state mutation, failing tests, subprocesses, long-running services, or remote/headless attach.
Pick the smallest debugger that reaches the bad frame.
Choose
breakpoint(): local code, source edits ok, fastest path.python3 -m pdb: no source edit, launch from the beginning.python3 -m pdb -c continue: stop at an unhandled exception.debugpy: remote/headless process, DAP client, already-running PID, or service startup race.
Commands
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>
For source-edit attach:
import debugpy
debugpy.listen(("127.0.0.1", 5678))
debugpy.wait_for_client()
debugpy.breakpoint()
For post-mortem:
import pdb, sys
try:
run()
except Exception:
pdb.post_mortem(sys.exc_info()[2])
raise
pdb
- Flow:
n,s,r,c,q. - Stack/source:
w,u,d,a,l,ll. - Values:
p expr,pp expr,display expr. - Breakpoints:
b file.py:42,b func,b file.py:42, condition,cl <num>. - Mutate/evaluate:
!statement; full REPL:interact.
Rules
- Reproduce with the smallest command/test first.
- Disable parallel test workers for pdb; interactive stdin usually breaks inside worker pools.
- Keep
debugpyin the active env; do not add it as a project dependency unless the project already wants it. - Bind debug servers to
127.0.0.1; do not expose0.0.0.0unless isolated or tunnelled. - Use unique ports for parallel sessions.
debugpy --pidinjects into a running process; confirm the target pid before attaching.- If PID attach fails on Linux, check ptrace/container privileges before changing the target.
- Cleanup before commit:
rg -n 'breakpoint\\(|pdb\\.set_trace|debugpy\\.' --type py. - Rerun the normal project test/gate without the debugger.
PYTHONBREAKPOINT=0disablesbreakpoint().- If a process is stuck after debugger detach, confirm it is not still paused at a breakpoint.
常见问题
我需要修改代码吗?
不一定。pdb 会话可以在不修改源代码的情况下开始,不过代码中的断点会更快。
它能调试正在运行的服务吗?
可以。debugpy 可以附加到正在运行的进程,或正在启动的服务。
开放调试端口安全吗?
技能使用本地地址 127.0.0.1 作为调试端口,因此只有你自己的电脑可以访问。
详情
作者的原始描述
Debug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote attach.
repo: openclaw/openclaw
热度
- GitHub 星标
- 394k
- 排名
- #76
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
discord-user-post
394k让你的智能体通过 Discord 桌面应用,以你的身份发送你已批准的消息,并在发送前确认具体频道。
discrawl
394k让你的智能体搜索和总结本地保存的 Discord 消息档案,查看档案的新旧程度,并阅读私信。
gitcrawl
394k让你的智能体搜索已保存的 GitHub 议题和拉取请求档案,将重复内容归类,并在 GitHub 上核实它们的当前状态。
graincrawl
394k让你的智能体搜索已保存的 Granola 会议记录和转写稿,查看它们的新旧程度,并统计某段时间内的数量。