python-debugpy
它能做什么
该技能教智能体如何使用 Python 内置调试器和远程调试器,查找 Python 程序中的缺陷。适用于被打印语句无法揭示的问题困扰的开发者。
适用场景
- ✓当 Python 程序给出错误结果,而原因隐藏时。
- ✓当 Python 测试失败,而你无法解释原因时。
- ✓当 Python 服务运行在另一台机器上,或启动顺序令人困惑,需要附加调试器时。
技能链接
https://github.com/EKKOLearnAI/ekko-studio/blob/main/packages/ekko-agent/skills/python-debugpy/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的 Python 脚本算出的总数不对。请帮我逐步检查,看看哪个值出了问题。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会为任务选择最简单的调试器,并在正确的行暂停程序,以便检查变量。对于正在运行的程序,它会在本地端口上附加远程调试器。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Python Debugging
Use when Python code needs interactive debugging: hidden locals, confusing state mutation, failing tests, subprocesses, long-running services, or remote attach.
Choose the smallest debugger that reaches the bad frame:
breakpoint(): local code where source edits are acceptable.python3 -m pdb: launch from the beginning without editing source.python3 -m pdb -c continue: stop at an unhandled exception.debugpy: remote/headless processes, DAP clients, an existing PID, or startup races.
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>
Source-edit attach:
import debugpy
debugpy.listen(("127.0.0.1", 5678))
debugpy.wait_for_client()
debugpy.breakpoint()
Post-mortem inspection:
import pdb
import sys
try:
run()
except Exception:
pdb.post_mortem(sys.exc_info()[2])
raise
pdb commands
- Flow:
n,s,r,c,q. - Stack and 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>. - Evaluate or mutate:
!statement; full REPL:interact.
Rules
- Reproduce with the smallest command or test first.
- Disable parallel test workers for pdb; worker pools usually break interactive stdin.
- Keep
debugpyin the active environment. Do not add it as a project dependency unless the project needs it. - Bind debug servers to
127.0.0.1; expose them only on an isolated network or through a secure tunnel. - Treat PID attach as process injection. Avoid security-sensitive or production targets unless explicitly approved.
- On Linux, check ptrace and container privileges before changing a target when PID attach fails.
- Before committing, run
rg -n 'breakpoint\\(|pdb\\.set_trace|debugpy\\.' --type pyand remove accidental breakpoints. - Rerun the normal project test gate without the debugger.
常见问题
我需要修改代码吗?
不一定。该技能可以在调试器中启动程序而不编辑代码,不过本地工作可能会在源代码中使用断点行。
它能调试已经在运行的程序吗?
能。调试器可以通过进程 ID 附加到已有的进程。
什么是事后调试?
它会在程序崩溃的那一刻打开调试器,以便你检查当时的状态。
详情
作者的原始描述
Debug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote or headless attach.
repo: EKKOLearnAI/ekko-studio
热度
- GitHub 星标
- 12k
- 排名
- #11575
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
1password
12k帮你的智能体使用 1Password CLI 为命令和配置文件获取机密信息,同时不在聊天、日志或已保存的文件中显示这些信息。
apple-notes
12k帮你的智能体在 Mac 上使用 memo 命令行工具创建、搜索、阅读、编辑、移动或删除 Apple 备忘录。
apple-reminders
12k帮你的智能体在 Mac 上使用 remindctl 工具列出、创建、编辑、完成或删除 Apple 提醒事项及提醒列表。
document-to-action-items
12k帮你的智能体把文档、会议记录或一组笔记,整理成一张清晰的任务、负责人、截止日期和决定的表格。