[SciPy-User] keyboard interrupt problem with odeint

Brian Blais bblais at bryant.edu
Mon Apr 12 19:27:49 EDT 2010


Hello,

I have a busy loop with odeint that I want to allow the user to stop,  
and then have the program return gracefully.  Unfortunately, when I  
try to catch the KeyboardInterrupt exception, it doesn't exit or  
catch it.  I paired the program down to the following silly example  
to reproduce the problem:

#==========
from scipy.integrate import odeint
from numpy import *


def damped_osc(u,t,b): #defines the system of odes
     x=u[0]
     v=u[1]
     return(v,-x-b*v) #the derivatives of u

t = arange(0,20,0.001)
u0 = array([1,0])
b=0.4
try:
     while True:
         u=odeint(damped_osc,u0,t,args=(b,)) #b is in tuple, needs comma
except KeyboardInterrupt:
     print "here!"
#==========

hitting control-C, I get the following printed to the screen:

error: Error occured while calling the Python function named damped_osc

but the thing keeps going!


Is there a way I can consistently stop it?


		thanks,

			Brian Blais

-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais
http://bblais.blogspot.com/



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100412/d5a95acc/attachment.html>


More information about the SciPy-User mailing list