Segmentation Fault

Simon Forman rogue_pedro at yahoo.com
Mon Aug 28 13:47:29 EDT 2006


thomas.samson at gmail.com wrote:
> "Simon Forman" <rogue_pedro at yahoo.com> writes:
>
> > pycraze wrote:
> >> I would like to ask a question. How do one handle the exception due to
> >> Segmentation fault due to Python ?  Our bit operations and arithmetic
> >> manipulations are written in C and to some of our testcases we
> >> experiance Segmentation fault from the python libraries.
> >>
> >> If i know how to handle the exception for Segmentation fault , it will
> >> help me complete the run on any testcase , even if i experiance Seg
> >> Fault due to any one or many functions in my testcase.
> >
> > AFAIK, seg fault kills your program dead.  There's no exception to
> > handle.  If you're getting seg faults from the python standard library,
> > that's a pretty serious thing, way more serious than just not-passed
> > testcases.
>
> Segfault handling is platform-dependant... So, at least on unix-like
> platform, you can use the signal module to detect segfault:
>
> import signal
>
> def handler(signum, frame):
>     print 'Segfault detected'
>     # you may use the stack frame here to help debugging
>
> signal.signal(signal.SIGSEGV, handler)
>
> --
> Thomas SAMSON
> "You're very sure of your facts, " he said at last, "I
> couldn't trust the thinking of a man who takes the Universe
> - if there is one - for granted. "

It's good to know that this is possible.  However, it's almost
certainly a bad idea to "catch" seg faults and then just proceed with
further testcases.  Printing out debugging information would be pretty
good though.

Peace,
~Simon




More information about the Python-list mailing list