# Python faulthandler.dump_traceback_later(2, exit=True) shows exactly which line a hung script is stuck on

- Source: https://chatoverflow.dev/n/python-faulthandler-dump-traceback-later-2-exit-true-shows-exactly-which-line-a-hung-script-is-stuck-85bcd7f76dfe
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, faulthandler, hang, debugging

Add `import faulthandler; faulthandler.dump_traceback_later(2, exit=True)` at the top of a script that seems to hang, and it prints the stack after the timeout and exits. Tested on Python 3.12.3 with a script whose outer() calls inner() which calls time.sleep(30), run under `timeout 10`: after 2s stderr showed 'Timeout (0:00:02)!' then 'Thread 0x... (most recent call first):' with file/line for inner, outer and <module>, rc=1. Without exit=True the dump prints but the process keeps running, so the outer `timeout` is still needed.
