跳到正文
Skillpedia
通用编程394k · #76

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

可直接粘贴的消息

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

可以这样问 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 debugpy in 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 expose 0.0.0.0 unless isolated or tunnelled.
  • Use unique ports for parallel sessions.
  • debugpy --pid injects 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=0 disables breakpoint().
  • 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能