Python Debugging Cheat Sheet/Dump stack traces for all threads

Useful when an app appears hung or deadlocked.

Section: Async, Web, and Production Troubleshooting

Dump stack traces for all threads

python
python
import faulthandler
import signal

faulthandler.register(signal.SIGUSR1)
Explanation

After registering a signal, send `SIGUSR1` to the process to dump thread stack traces.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Async, Web, and Production Troubleshooting
Enable asyncio debug mode
Expose slow callbacks and event-loop issues.
OpenIn sheetbashsame section
Enable debug mode programmatically
Turn on event loop debugging in code.
OpenIn sheetpythonsame section
Start a simple HTTP server for quick testing
Serve files locally to reproduce client behavior.
OpenIn sheetbashsame section
Profile import time
See which imports are slowing startup.
OpenIn sheetbashsame section
Insert a built-in breakpoint
Pause execution and enter the configured debugger.
Print the current exception traceback
Dump the active exception traceback in an except block.