문제

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

PyErr_Print()
PyErr_SetString(errobj, message)

in ode_function, but then the code segfaults. As I understand it, what's supposed to happen next is for ode_function to return NULL or -1 or something. However, LSODA expects ode_function to be void.

This is an attempt to patch scipy.integrate.odeint, based on this question that I asked previously.

도움이 되었습니까?

해결책

pv on this Github issue for Scipy explained what the issues are. In short, setjump() and longjump() in C could do this in principle, but this is error-prone, notably not being threadsafe. This may be of use in other similar applications, but using f2py is generally the better way to get Fortran code to communicate with Python.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top