I ran into a very odd issue. If I have the following C and Python codes:
#include <Python.h>
int main(int argc, char *argv[])
{
Py_Initialize();
FILE* to_run_script= fopen("script.py", "r");
if (to_run_script != NULL)
PyRun_SimpleFile(to_run_script, "script.py");
Py_Finalize();
return 0;
}
and
def func1():
print("numpy NOT YET imported!!n")
import numpy
print("numpy is imported!!n")
return 1.5
func1()
Then everything works as expected, Python starts and I get both output lines.
However, when I embed the same piece of code in our code (which does some setup, but I’m not exactly sure what) then the import numpy
statement throws a SIGFPE (more precisely, FPE_FLTOVF, at least that’s what strace says) and the code exits without printing the second line.
To further muddy the waters, if I run through valgrind the very same code that produced SIGFPE, then everything works again.
At this point I’m baffled and would be glad for any suggestions for what I should check.
6