[Python-Dev] Trap SIGSEGV and SIGFPE

Victor Stinner victor.stinner at haypocalc.com
Thu Dec 11 10:34:24 CET 2008


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 :-)

I guess that sigsetjmp() and siglongjmp() hack can be avoided in 
Py_EvalFrameEx(), so ceval.c could be unchanged.

New pseudocode:
  set checkpoint
  if error:
     get the backtrace
     display the backtrace
     fast exit (eg. don't call atexit, don't free memory, ...)
  else:
     normal execution

-- 
Victor Stinner aka haypo
http://www.haypocalc.com/blog/


More information about the Python-Dev mailing list