본문으로 건너뛰기
cccskills
무료GitHub에 공개

python-debugpy

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

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md4.3 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Python Debugger (pdb + debugpy)

Overview

Three tools, picked by situation:

ToolWhen
breakpoint() + pdbLocal, interactive, simplest. Add breakpoint() in source, run, get REPL.
python -m pdbLaunch script under pdb with no source edits.
debugpyRemote / headless / attach to running process. DAP, scriptable.

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 misbehaves and you can't restart it
  • Post-mortem: an exception fired and you want to inspect locals at crash site
  • A subprocess 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)):

CommandAction
h / h cmdhelp
nnext line (step over)
sstep into
rreturn from current function
ccontinue
unt Ncontinue until line N
j Njump to line N (same function only)
b Nset breakpoint at line N
b file:Nset breakpoint in another file
b funcset breakpoint at function
cl Nclear breakpoint N
llist 11 lines around current
lllist whole function
w / whereshow call stack
u / dmove up/down stack frame
p exprprint expression
pp exprpretty-print expression
aprint args of current function
argssame as a
display exprwatch expression (re-eval each step)
interactdrop into interactive Python REPL

Using breakpoint()

def process(data):
    result = transform(data)
    breakpoint()  # Execution pauses here, pdb REPL opens
    return result

Run normally:

python script.py
# Pauses at breakpoint(), (Pdb) prompt appears

Using python -m pdb (no source edits)

python -m pdb script.py
# Starts paused at first line

Post-mortem debugging

Drop into pdb at the exact exception site:

import pdb, traceback
try:
    main()
except Exception:
    traceback.print_exc()
    pdb.post_mortem()

Or:

python -m pdb -c continue script.py
# Runs until exception, then drops to pdb at the crash

debugpy (remote attach)

For long-running processes or headless debugging:

# Install
pip install debugpy

# Option 1: Launch with debugpy
python -m debugpy --listen 5678 --wait-for-client script.py

# Option 2: Inject into running code
import debugpy
debugpy.listen(5678)
print("Waiting for debugger on port 5678...")
debugpy.wait_for_client()

Attach from another terminal (DAP client):

# Using debugpy's CLI to set breakpoints + continue
python -m debugpy --connect localhost:5678 --set-breakpoint script.py:42

Or use any DAP-compatible editor (VS Code, Neovim) to attach to port 5678.

Common Debugging Patterns

Watch a variable change

# In pdb
(Pdb) display my_list
# Each step, pdb re-evaluates and shows the value if changed

Conditional breakpoint

# In source
breakpoint() if condition else None

# Or in pdb
(Pdb) b 42, x > 100  # Break at line 42 only when x > 100

Inspect a running subprocess

import debugpy
# In the subprocess code:
debugpy.listen(5679)
debugpy.wait_for_client()
# Parent can attach to port 5679

Pitfalls

  • breakpoint() in production: remove before commit. Use breakpoint() only for local debugging.
  • pdb + multiprocessing: child processes don't inherit the pdb prompt. Use debugpy for multi-process debugging.
  • pdb + asyncio: pdb works but async stack traces can be confusing. Use w (where) to see the full async call stack.
  • Windows + pdb: some pdb features work differently on Windows. python -m pdb is more reliable than breakpoint() in some Windows terminals.
  • debugpy port conflicts: default port 5678 may be taken. Use --listen 5679.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Structured peer-review of academic papers.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

Dark-themed SVG architecture/cloud/infra diagrams as HTML.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

arxiv

무료

Search arXiv papers by keyword, author, category, or ID.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

Monitor blogs and RSS/Atom feeds via blogwatcher-cli.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

bootstrap

무료

Onboarding conversation to generate a user profile.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

Generate charts: select type, extract data, render image.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

HezaoHezao/poirot2512026년 7월 29일 업데이트

HezaoHezao의 스킬 모두 보기

이 스킬의 문제 신고