跳到正文
Skillpedia
API 与服务器(后端)12k · #11575

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/EKKOLearnAI/ekko-studio/blob/main/packages/ekko-agent/skills/python-debugpy/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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 debugpy in 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 py and 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能