Raise exception and stop execution in Python C API code

I have code that has two Python functions, run () and dudt (u, t, ...). run calls the C function, odepack_odeint, which calls the Fortran subroutine, LSODA, which calls another C function, ode_function, which calls dudt. If there is an error in dudt, it can be printed with ode_function using PyErr_Print (), but I cannot figure out how to say that the code will stop execution. I tried,

PyErr_Print() PyErr_SetString(errobj, message) 

in ode_function, but then the segfaults code. As far as I understand, it should happen that ode_function will return NULL or -1 or something else. However, LSODA expects the ode_function to be invalid.

This is an attempt to fix scipy.integrate.odeint based on this question that I asked earlier.

+3
source share
1 answer

pv on this issue Github for Scipy explained what the problems are. In short, setjump () and longjump () in C could do this in principle, but this is error prone, especially not being thread safe. This may be useful in other similar applications, but using f2py is usually the best way to get Fortran code to communicate with Python.

0
source

Source: https://habr.com/ru/post/1479566/


All Articles