more informative stack traces

Fernando Perez fperez528 at yahoo.com
Tue Apr 15 18:21:50 CEST 2003


Skip Montanaro wrote:


> Everyone involved should take a look at the cgitb module in the standard
> distribution.  I submitted a patch for cgitb a long time ago which allows
> plain text traceback generation:
> 
>     http://python.org/sf/569574
> 
> Note Ping's comment appended to that patch that the core code belongs in
> the traceback module.
> 
> If you can get this sorted out quickly so that the core code is in the
> traceback module I suspect you can still squeeze it into 2.3.

Well, if you want to take a look at ipython (http://ipython.scipy.org), it
already has a text (with optional coloring where supported) version of
this.  The code was originally written by Nathan Grey, and he marked is as
being lifted off cgitb.py.  I've later modified it quite a bit.  After
becoming used to ipython, I find it nearly impossible to work with regular
tracebacks.

Here is an example comparing the ipython traceback (and on myscreen it is
color highlighted):

In [2]: 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()
        global __name__ = '__main__', main = <function 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)
        global RampNum = <function RampNum>, array_num = array([ 0.,  0., 
0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]), size = 10
    107     RNtime = time.clock()-t0
    108     print 'RampNum time:', RNtime

/usr/local/home/fperez/test/error.py in RampNum(result=array([ 0.,  0.,  0., 
0.,  0.,  0.,  0.,  0.,  0.,  0.]), size=10, start=0.0, end=1.0)
     88     tmp = zeros(1e2)
     89     step = (end-start)/(size-1-tmp)
---> 90     result[:] = arange(size)*step + start
        result = array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]),
global arange = <built-in function arange>, size = 10, step = array([
0.11111111,  0.11111111,  0.11111111,  0...11111111,  0.11111111, 
0.11111111,  0.11111111]), start = 0.0
     91
     92 def main():

ValueError: frames are not aligned
WARNING: Failure executing file: <error.py>


to the same traceback from plain python:

[~/test]> python error.py
hi
Ramp time: 0.0
Traceback (most recent call last):
  File "error.py", line 113, in ?
    if __name__ == '__main__': main()
  File "error.py", line 106, in main
    RampNum(array_num, size, 0.0, 1.0)
  File "error.py", line 90, in RampNum
    result[:] = arange(size)*step + start
ValueError: frames are not aligned

This code is ready, it works, and it has been in use by ipython's users for
about 1 1/2 years.  Feel free to take a look at it.

Best,

f.




More information about the Python-list mailing list