Community程式設計與開發github.com

python-debugpy

使用 pdb、breakpoint()、事後檢驗與 debugpy 遠端附加來除錯 Python 程式碼。

python-debugpy 是什麼?

此技能提供一套完整的 Python 除錯方案,涵蓋從最輕量的 `breakpoint()` 到支援遠端/無頭(headless)進程的 `debugpy` 等不同情境。開發者可以根據問題發生的位置與環境,選擇最適合的除錯器:快速修改原始碼時可用 `breakpoint()`;不需修改原始碼時可用 `pdb` 模組以命令列啟動並設定例外中斷點;而 `debugpy` 則能附加至正在執行的遠端進程或服務啟動時的競爭條件(race condition)。技能文件整理了各種常用指令(如 pdb 單步執行、變數檢視、中斷點管理)與實務規則,例如先用最簡單的指令重現問題、在平行測試中停用除錯器以避免 stdin 衝突、除錯伺服器僅綁定 127.0.0.1、清理程式碼中的除錯殘留等,幫助開發者在本地、遠端及容器環境中有效率地診斷與修復問題。

相容平台~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 程式碼需要互動式除錯時使用:隱藏的區域變數、令人困惑的狀態變更、失敗的測試、子程序、長時間運行的服務,或遠端/無頭(headless)附加。

選擇能夠到達問題幀(frame)的最小除錯器。

選擇

  • breakpoint():本地程式碼,可編輯原始碼,最快路徑。
  • python3 -m pdb:不需編輯原始碼,從頭啟動。
  • python3 -m pdb -c continue:在未處理的例外處停止。
  • debugpy:遠端/無頭進程、DAP 客戶端、已運行的 PID,或服務啟動時的競爭條件(race condition)。

指令

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>

對於原始碼編輯附加(attach):

import debugpy

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

對於事後檢驗(post-mortem):

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。

規則

  • 先用最小的指令或測試重現問題。
  • 停用平行測試 worker 以使用 pdb;互動式 stdin 通常會在 worker pool 內中斷。
  • 將 debugpy 放在活躍的環境中;除非專案本身已經需要它,否則不要將其加入專案依賴。
  • 將除錯伺服器綁定到 127.0.0.1;除非在隔離環境或隧道中,否則不要暴露 0.0.0.0。
  • 對並行工作階段(session)使用不同的通訊埠。
  • debugpy --pid 會注入到正在運行的進程中;附加前請確認目標 PID。
  • 如果在 Linux 上 PID 附加失敗,請先檢查 ptrace/容器權限,再考慮變更目標。
  • 提交前清理:rg -n 'breakpoint\(|pdb\.set_trace|debugpy\.' --type py。
  • 重新執行不含除錯器的正常專案測試/閘道(gate)。
  • PYTHONBREAKPOINT=0 可停用 breakpoint()。
  • 如果進程在除錯器分離(detach)後停住,請確認它並非仍暫停於中斷點上。

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.

相關技能