Testing and Diagnostics Modules
faulthandler
Emits low-level Python stack diagnostics, including on selected fatal faults or explicit requests. Unlike ordinary traceback formatting it can write to a file descriptor even when normal Python execution is compromised. Keep output files open while registered; stack dumps may reveal paths. This example requests a harmless dump to a temporary file.
Formal Syntax & Structure
python syntaxpython
import faulthandlerReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import faulthandlerfrom tempfile import TemporaryFilewith TemporaryFile() as output: faulthandler.dump_traceback(output, all_threads=False) output.seek(0) print(bool(output.read()))