[Python-Dev] News of the faulthandler project

Victor Stinner victor.stinner at haypocalc.com
Thu Feb 3 14:05:06 CET 2011


Hi,

Since the end of last december, I'm still working on my fault handler
project:
https://github.com/haypo/faulthandler

You can use it to get more information after a crash or if you program
hangs somewhere. It helps if you don't have access to other debugging
tool (eg. install gdb7+python-gdb.py on Windows is not trivial today) or
if you cannot interact with your program (eg. on a buildbot).

The last version works on Python 2.5, 2.6, 2.7, 3.1 and 3.2, on Windows,
Linux and FreeBSD. It can display the Python backtrace on a fatal fault
(SIGSEGV, SIGFPE, SIGILL, SIGBUS), after a delay in seconds, when an
user signal is received (eg. SIGUSR1) or explicitly (call directly the
dumpbacktrace() function).

By default, it is disabled: you have to call faulthandler.enable() to
install the signal handlers. You can choose in which file the backtrace
is written (sys.stderr by default) and if it displays the backtrace of
the current thread or of all threads. If you use the delay: you can
choose to repeat the operation (dump the backtrace each delay seconds).

The project is now a module, so it is no more enabled by default. It is
more configurable, and has more features. It has a better API (so it was
a good idea to not include it in Python 3.2).

I plan to integrate this project into Python 3.3. I hope that it can
help to debug some buildbots issues, but also any segfault in your
programs.

Note: faulthandler.register() (dump the backtrace when an user signal is
raised) is only available in the development version.

--

The project is not perfect yet:

 - I have to write something to be able to enable the faulthandler
before starting your program (write a program for that?)
 - faulthandler.dumpbacktrace_later() uses alarm() which interrupts the
current system call when SIGALARM is raised: it may be a problem (it's
maybe not a problem if you try to debug a program hang)
 - I don't know if something should be done on a fork()
 - SIGABRT is not handled
 - The module is unloaded using Py_AtExit(): it cannot release
references because the unload function is called too late

--

There are similar projects, tipper and crier, using a signal handler
implemented in Python or a signal handler implemented in Python. These
projects give more information (eg. local variables) and more control on
how the informations are written, but I think that there are less
reliable: it doesn't work if Python hangs (eg. deadlock) and signal
handlers implemented in Python are asynchronous. And there are unable to
catch fatal faults (eg. SIGSEGV).

http://pypi.python.org/pypi/tipper/
https://gist.github.com/737056

Victor



More information about the Python-Dev mailing list