Chuyển đến nội dung
Skillpedia
Lập trình chung394k · #76

python-debugpy

Skill này làm gì

Skill hướng dẫn một agent AI dùng các công cụ gỡ lỗi Python, gồm pdb và debugpy, để tạm dừng mã và xem trạng thái của nó. Dành cho lập trình viên cần tìm lỗi khó hiểu trong mã hoặc dịch vụ Python.

Khi nào nên dùng

  • ✓Khi một script Python hoạt động kỳ lạ và bạn cần xem giá trị tại một điểm nhất định.
  • ✓Khi một bài kiểm thử Python thất bại và bạn muốn chạy từng bước qua nó.
  • ✓Khi một dịch vụ Python chạy lâu cần được gắn vào trình gỡ lỗi từ xa.

Liên kết skill

https://github.com/openclaw/openclaw/blob/main/skills/python-debugpy/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/openclaw/openclaw/blob/main/skills/python-debugpy/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Script Python của tôi cho ra số sai. Hãy giúp tôi tạm dừng nó đúng chỗ và cho tôi xem giá trị các biến.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chọn trình gỡ lỗi nhỏ nhất có thể tới được vấn đề, chẳng hạn một phiên pdb hoặc breakpoint trong mã. Sau đó nó chạy từng bước chương trình, kiểm tra giá trị và đề xuất cách sửa.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
Câu hỏi thường gặp

Tôi có cần sửa mã không?

Không phải lúc nào cũng cần. Một phiên pdb có thể bắt đầu mà không cần sửa mã, dù breakpoint trong mã nhanh hơn.

Nó có gỡ lỗi được dịch vụ đang chạy không?

Có. debugpy có thể gắn vào một tiến trình đang chạy hoặc một dịch vụ đang khởi động.

Mở cổng gỡ lỗi có an toàn không?

Skill dùng địa chỉ cục bộ 127.0.0.1 cho cổng gỡ lỗi, nên chỉ máy của bạn mới truy cập được.

Chi tiết

Mô tả gốc của tác giả

Debug Python with pdb, breakpoint(), post-mortem inspection, and debugpy remote attach.

repo: openclaw/openclaw

Độ phổ biến

Sao GitHub
394k
Vị trí xếp hạng
#76
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự