본문으로 건너뛰기
Skillpedia
일반 코딩260k · #574

python-debugpy

하는 일

이 스킬은 코드를 멈추고 값을 검사해 AI가 Python 프로그램의 버그를 찾도록 돕습니다. print 문으로는 문제가 드러나지 않는 개발자를 위한 것입니다.

사용하는 경우

  • ✓Python 테스트가 실패하고 트레이스백만으로는 값이 왜 잘못되었는지 알 수 없을 때.
  • ✓함수를 단계별로 따라가며 실행 중 데이터가 바뀌는 것을 보고 싶을 때.
  • ✓오래 실행되는 Python 프로세스가 잘못 작동하는데 재시작할 수 없을 때.

스킬 링크

https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/software-development/python-debugpy/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/software-development/python-debugpy/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 Python 함수가 잘못된 리스트를 반환하는데 print 문으로는 원인을 모르겠어요. 함께 단계별로 살펴봐 주실래요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 Python의 내장 pdb 디버거를 씁니다. 코드에 중단점을 두거나 pdb로 스크립트를 실행해 시작합니다. 이미 실행 중인 프로세스에는 debugpy 도구로 원격 연결합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Python Debugger (pdb + debugpy)

Overview

Three tools, picked by situation:

Tool When
breakpoint() + pdb Local, interactive, simplest. Add breakpoint() in the source, run normally, get a REPL at that line.
python -m pdb Launch an existing script under pdb with no source edits. Useful for quick poking.
debugpy Remote / headless / "attach to already-running process." Talks DAP, scriptable from terminal, works for long-lived processes (gateway, daemon, PTY children).

Start with breakpoint(). It's the cheapest thing that works.

When to Use

  • A test fails and the traceback doesn't reveal why a value is wrong
  • You need to step through a function and watch a collection mutate
  • A long-running process (hermes gateway, tui_gateway) misbehaves and you can't restart it
  • Post-mortem: an exception fired in prod-ish code and you want to inspect locals at the crash site
  • A subprocess / child (Python _SlashWorker, PTY bridge worker) is the actual bug site

Don't use for: things print() / logging.debug solve in under a minute, or things pytest -vv --tb=long --showlocals already reveals.

pdb Quick Reference

Inside any pdb prompt ((Pdb)):

Command Action
h / h cmd help
n next line (step over)
s step into
r return from current function
c continue
unt N continue until line N
j N jump to line N (same function only)
l / ll list source around current line / full function
w where (stack trace)
u / d move up / down in the stack
a print args of the current function
p expr / pp expr print / pretty-print expression
display expr auto-print expr on every stop
b file:line set breakpoint
b func break on function entry
b file:line, cond conditional breakpoint
cl N clear breakpoint N
tbreak file:line one-shot breakpoint
!stmt execute arbitrary Python (assignments included)
interact drop into full Python REPL in current scope (Ctrl+D to exit)
q quit

The interact command is the most powerful — you can import anything, inspect complex objects, even call methods that mutate state. Locals are read-only by default; use !x = 42 from the (Pdb) prompt to mutate.

Recipe 1: Local breakpoint

Easiest. Edit the file:

def compute(x, y):
    result = some_helper(x)
    breakpoint()           # <-- drops into pdb here
    return result + y

Run the code normally. You land at the breakpoint() line with full access to locals.

Don't forget to remove breakpoint() before committing. Use git diff or a pre-commit grep:

rg -n 'breakpoint\(\)' --type py

Recipe 2: Launch a script under pdb (no source edits)

python -m pdb path/to/script.py arg1 arg2
# Lands at first line of script
(Pdb) b path/to/script.py:42
(Pdb) c

Recipe 3: Debug a pytest test

Use terminal and the canonical runner for noninteractive diagnostics:

# Show locals in tracebacks without pdb:
scripts/run_tests.sh tests/path/to/test_file.py --showlocals --tb=long

scripts/run_tests.sh captures each file in a separate subprocess, so --pdb or --trace cannot provide an interactive prompt there. For an interactive debugger only, use the independent development/test interpreter prepared in Recipe 5 (never a production generation):

.venv/bin/python -m pytest tests/foo_test.py::test_bar --pdb

This bypasses the hermetic-env guarantees — fine for debugging, but re-run under the wrapper to confirm before pushing.

Recipe 4: Post-mortem on any exception

import pdb, sys
try:
    run_the_thing()
except Exception:
    pdb.post_mortem(sys.exc_info()[2])

Or wrap a whole script:

python -m pdb -c continue script.py
# When it crashes, pdb catches it and you're in the frame of the exception

Or set a global hook in a repl/jupyter:

import sys
def excepthook(etype, value, tb):
    import pdb; pdb.post_mortem(tb)
sys.excepthook = excepthook

Recipe 5: Remote debug with debugpy (attach to running process)

For long-lived processes: Hermes gateway, tui_gateway, a daemon, a process that's already misbehaving and can't be restarted clean.

Setup

For Hermes, use a separate development checkout and data home, not a live production generation. Follow the [PM developer workflow](https://hermes-agent.nousres

자주 묻는 질문

가장 간단한 시작 방법은 무엇인가요?

스킬은 코드에 breakpoint() 줄을 추가하고 평소처럼 실행하라고 말하며, 그러면 그 줄에서 디버거 프롬프트가 열립니다.

debugpy는 무엇에 쓰나요?

스킬은 debugpy를 원격이나 헤드리스 디버깅, 이미 실행 중인 프로세스에 씁니다.

언제 쓰지 말아야 하나요?

스킬은 print 문이나 pytest 출력으로 1분 안에 드러나는 문제에는 쓰지 말라고 합니다.

상세 정보

작성자의 원본 설명

Debug Python: pdb REPL + debugpy remote (DAP).

repo: NousResearch/hermes-agent

인기도

GitHub 스타
260k
순위
#574
라이선스
MIT
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬