Python Glossary Русский

Python 3.14+faulthandlerfunction

faulthandler.dump_c_stack()

dumping the stack

Writes the C-level call stack of the current thread to a file — functions of the interpreter itself and of extensions. Available since Python 3.14.

Syntax

faulthandler.dump_c_stack(file=sys.stderr)

It shows what a Python traceback cannot: which C function of an extension the program got stuck or crashed in. It does not work everywhere: without backtrace(3) or with an unsupported compiler an error message is printed instead of the stack, no exception is raised. With rich debug info the dump can be very slow. Since 3.14 enable() prints this stack on a crash itself (c_stack=True).

Examples

# Python 3.14+
import faulthandler
with open('cstack.txt', 'w') as f:
    faulthandler.dump_c_stack(file=f)
text = open('cstack.txt').read()
print(len(text) > 0)  # → True
print(text.splitlines()[0])  # → ? Current thread's C stack trace (most recent call first):

See also

Open in the full glossarydocs.python.orgReport an inaccuracy