dropping into the debugger on an exception

Fernando Perez fperez528 at yahoo.com
Thu Jun 10 03:23:26 CEST 2004


Jon Perez wrote:

> (sorry for the duplicate post, just wanted to make the subject
> line clearer)
> 
> How do you set up pdb such that you will automatically
> get dropped into its prompt if an unanticipated exception
> occurs in a script you are using?

You may want to try out ipython (http://ipython.scipy.org).  It does exactly
what you want (and a lot more):

In [1]: cd ~/test
/usr/local/home/fperez/test

In [2]: pdb
Automatic pdb calling has been turned ON

In [3]: run error
hi
Ramp time: 0.0
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/usr/local/home/fperez/test/error.py
    109
    110     print 'speedup:',Rtime/RNtime
    111
    112
--> 113 if __name__ == '__main__': main()

/usr/local/home/fperez/test/error.py in main()
    104     array_num = zeros(size,'d')
    105     for i in xrange(reps):
--> 106         RampNum(array_num, size, 0.0, 1.0)
    107     RNtime = time.clock()-t0
    108     print 'RampNum time:', RNtime

/usr/local/home/fperez/test/error.py in RampNum(result, size, start, end)
     88     tmp = zeros(1e2)
     89     step = (end-start)/(size-1-tmp)
---> 90     result[:] = arange(size)*step + start
     91
     92 def main():

ValueError: frames are not aligned
> /usr/local/home/fperez/test/error.py(90)RampNum()
-> result[:] = arange(size)*step + start
(Pdb) print start
0.0


You can then quit pdb, type 'pdb' again to disable the feature, and move on.

Cheers,

f



More information about the Python-list mailing list