Detailed traceback

Fernando Perez fperez.net at gmail.com
Tue Sep 13 20:51:03 CEST 2005


Echo wrote:

> I have been working on handling unhanded exceptions and making a
> detailed print out of the traceback after the exception. I found that
> traceback.extract_tb worked nice and was quite simple.
> 
> During my searching around I found out that it might be possible to
> get the variables and their respective values for each frame. I found
> this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215 to
> be extremely helpful.
> 
> My only problem with that is that there appears to be no way to get
> the line of code for a frame.
> 
> So I was wondering if it was possible to get the line of code for a frame.

You might not want to reinvent that particular wheel from scratch.  While not
rocket science, getting locals/globals correctly requires relatively careful
code (it took me quite a few tries to get it right in all possible cases)..

IPython's ultraTB module does everything you're asking for, and its
CrashHandler module even wraps the whole thing into a tidy file ready for
email to the developers.

Feel free to use it, it's all BSD licensed after all.

Cheers,

f

ps - suggestion for an enterprising user looking for a project: clean up
ultraTB a little, isolate its ANSI terminal dependencies better (probably
wrapped up in an abstract markup for coloring), and package it standalone. 
This question pops up every two weeks here, this makes me suspect that the
need for better traceback printing than the primitive stuff supplied by the
stdlib is real.  Since ultraTB is just an offshoot of cgitb, it would be a
nice way to give back to the stdlib.

I'll be glad to help (though it's easy), but right now I just don't have the
time to do it myself.




More information about the Python-list mailing list