[SciPy-User] signal handling inside integrate.odeint

Colin Cotter colinjcotter@gmail....
Sat Aug 22 11:44:10 CDT 2009

Dear SciPy-user list,

  I have a question about handling signals with integrate.odeint. I am
developing some Monte-Carlo code that involves repeated calls off this
subroutine, but I seem to be doing something wrong with the signal
handling because if I hit ctrl-c during runtime, the code just jumps
out of odeint and continues with the loop. What is the best way to
deal with this i.e. how do I modify the code so that if I hit ctrl-c
during runtime the python script exits?

I have attached a piece of test code which exhibits this behaviour at
the bottom of this email.

best wishes
--Colin Cotter

from scipy import *

def myvec(x,t):
    for a in range(1000):
    return sin(x)

Y0 = 0.1*2*pi*arange(10.0)
    Y1 = integrate.odeint(myvec, Y0, t=array([0,1.0]),
                          rtol=1.0e-1, atol=1.0e-1, \
                          h0=0.01, hmax=0.2)

More information about the SciPy-User mailing list