[Python-Dev] Trap SIGSEGV and SIGFPE

Adam Olsen rhamph at gmail.com
Thu Dec 11 19:15:22 CET 2008

On Thu, Dec 11, 2008 at 2:34 AM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> Le Wednesday 10 December 2008 20:04:00 Terry Reedy, vous avez écrit :
>> >> Recover after a segfault is dangerous, but my first goal was to get the
>> >> Python backtrace instead just one line: "Segmentation fault". It helps a
>> >> lot for debug!
>> >
>> > Exactly! That's why it doesn't belong in the Python core. We can't
>> > guarantee anything about its affects or encourage it.
>> Would it be safe to catch SIGSEGV, output a trace, and then exit?
>> IE, make the 'first goal' the only goal?
> Oh yeah, good idea :-) Does it mean that Python interpreter can't be used to
> display the trace? It would be nice to -at least- use the Python stderr
> (which is written in pure Python for Python3). It would be better if the user
> can setup a callback, like sys.excepthook. But if -as many people wrote-
> Python is totally broken after a segfault, it is maybe not a good idea :-)

You have to use the low-level stderr, nothing that invokes Python.
I'd hate to get a second segfault while printing the first.

Just think about how indirect refcounting bugs tend to be.  Another
example is messing up GIL handling.  There's heaps of things for which
we'd want good stack traces, which can't be done from Python.

Adam Olsen, aka Rhamphoryncus

More information about the Python-Dev mailing list