diff --git a/Doc/library/faulthandler.rst b/Doc/library/faulthandler.rst --- a/Doc/library/faulthandler.rst +++ b/Doc/library/faulthandler.rst @@ -9,7 +9,7 @@ fault, after a timeout or on a user sign install fault handlers for :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. +using the :option:`-X faulthandler <-X>` 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 @@ -18,14 +18,14 @@ dump the traceback even on a stack overf The fault handler is called on catastrophic cases and so can only use signal-safe functions (e.g. it cannot allocate memory on the heap). That's why -the traceback is limited: only support ASCII encoding (use the -``backslashreplace`` error handler), limit each string to 100 characters, don't +the traceback is limited: it supports only ASCII encoding (using the +``backslashreplace`` error handler), limits each string to 100 characters, doesn't print the source code (only the filename, the function name and the line -number), limit to 100 frames and 100 threads. +number), and limits to 100 frames and 100 threads. By default, the Python traceback is written to :data:`sys.stderr`. Start your graphical applications in a terminal and run your server in foreground to see -the traceback, or specify a log file to :func:`faulthandler.enable()`. +the traceback, or specify a log file when calling :func:`faulthandler.enable()`. The module is implemented in C to be able to dump a traceback on a crash or when Python is blocked (e.g. deadlock). @@ -33,8 +33,8 @@ when Python is blocked (e.g. deadlock). .. versionadded:: 3.3 -Dump the traceback ------------------- +Dumping the traceback +--------------------- .. function:: dump_traceback(file=sys.stderr, all_threads=True) @@ -63,8 +63,8 @@ Fault handler state Check if the fault handler is enabled. -Dump the tracebacks after a timeout ------------------------------------ +Dumping the tracebacks after a timeout +-------------------------------------- .. function:: dump_tracebacks_later(timeout, repeat=False, file=sys.stderr, exit=False) @@ -84,8 +84,8 @@ Dump the tracebacks after a timeout Cancel the last call to :func:`dump_tracebacks_later`. -Dump the traceback on a user signal ------------------------------------ +Dumping the traceback on a user signal +-------------------------------------- .. function:: register(signum, file=sys.stderr, all_threads=True) @@ -104,8 +104,8 @@ Dump the traceback on a user signal Not available on Windows. -File descriptor issue ---------------------- +Issue with file descriptors +--------------------------- :func:`enable`, :func:`dump_tracebacks_later` and :func:`register` keep the file descriptor of their *file* argument. If the file is closed and its file @@ -117,15 +117,18 @@ these functions again each time that the Example ------- -Example of a segmentation fault on Linux: :: +.. highlight:: sh - $ python -q -X faulthandler - >>> import ctypes - >>> ctypes.string_at(0) +Example of a segmentation fault on Linux with and without enabling the fault +handler:: + + $ python3 -c "import ctypes; ctypes.string_at(0)" + Segmentation fault + + $ python3 -X faulthandler -c "import ctypes; ctypes.string_at(0)" Fatal Python error: Segmentation fault Current thread 0x00007fb899f39700: - File "/home/python/cpython/Lib/ctypes/__init__.py", line 486 in string_at + File "/usr/local/lib/python3.3/ctypes/__init__.py", line 486 in string_at File "", line 1 in Segmentation fault -