install fault handlers for the :const:`SIGSEGV`, :const:`SIGFPE`,
:const:`SIGABRT`, :const:`SIGBUS`, and :const:`SIGILL` signals. You can also
enable them at startup by setting the :envvar:`PYTHONFAULTHANDLER` environment
-variable or by using :option:`-X` ``faulthandler`` command line option.
+variable or by using the :option:`-X` ``faulthandler`` command line option.
The fault handler is compatible with system fault handlers like Apport or the
Windows fault handler. The module uses an alternative stack for signal handlers
Python is deadlocked.
-Dump the traceback
-------------------
+Dumping the traceback
+---------------------
.. function:: dump_traceback(file=sys.stderr, all_threads=True)
Check if the fault handler is enabled.
-Dump the tracebacks after a timeout
------------------------------------
+Dumping the tracebacks after a timeout
+--------------------------------------
.. function:: dump_traceback_later(timeout, repeat=False, file=sys.stderr, exit=False)
Cancel the last call to :func:`dump_traceback_later`.
-Dump the traceback on a user signal
------------------------------------
+Dumping the traceback on a user signal
+--------------------------------------
.. function:: register(signum, file=sys.stderr, all_threads=True, chain=False)
Not available on Windows.
-File descriptor issue
----------------------
+Issue with file descriptors
+---------------------------
:func:`enable`, :func:`dump_traceback_later` and :func:`register` keep the
file descriptor of their *file* argument. If the file is closed and its file
Example
-------
-Example of a segmentation fault on Linux: ::
+.. highlight:: sh
+
+Example of a segmentation fault on Linux with and without enabling the fault
+handler::
+
+ $ python3 -c "import ctypes; ctypes.string_at(0)"
+ Segmentation fault
- $ python -q -X faulthandler
+ $ python3 -q -X faulthandler
>>> import ctypes
>>> ctypes.string_at(0)
Fatal Python error: Segmentation fault