Catching floating point errors from linked C code

John Pye john.pye at gmail.com
Wed Jan 24 22:37:23 EST 2007


Hi all

I have some C code that is giving me some 'nan' values in some
calculations.  The C code is wrapped using SWIG to give me a Python
module that I am then exercising through a unittest suite.

It seems that I should expect the C code to throw floating point
exceptions (SIGFPE) and either the whole thing to abort, or for Python
to catch the errors and report them. Instead I'm getting neither. I
want to be able to track down the exact location of problems in my C
code.

Is there something that Python does to turn on/off the catching of
divide-by-zero errors, eg by manipulating <signal.h> signal handlers
and/or <fenv.h> settings?

Cheers
JP




More information about the Python-list mailing list