[Python-ideas] Compressing excepthook output

Steven D'Aprano steve at pearwood.info
Mon Sep 16 02:07:55 CEST 2013


On Mon, Sep 16, 2013 at 01:39:46AM +0200, אלעזר wrote:
> I suggest adding an excepthook that prints out a compressed version of the
> stack trace. The new excepthook should be the default at least for
> interactive mode.
[...]
> I have tried to implement an alternative for sys.excepthook (see below),
> which compresses the last simple cycle in the call graph. Turns out it's
> not trivial, since the traceback object is not well documented (and maybe
> it shouldn't be, as it is an implementation detail) so it's non trivial (if
> at all possible) to change the trace list in an existing traceback. I don't
> think it is reasonable to just send anyone interested in such a feature to
> implement it themselves - especially given that newcomers ate its main
> target - and even if we do, there is no simple way to make it a default.

I like where this is going. Tracebacks for recursive function calls 
are extremely noisy, with the extra lines rarely giving any useful 
information. 

Have a look at the cgitb module in the standard library.

I think you should start off by cleaning up your traceback handler to be 
less "ugly and fragile" (your words), if possible, and then consider 
publishing it on ActiveState's website as a Python recipe. That would be 
the first step in gathering user feedback and experience in the real 
world, and if it turns out to be useful in practice, at a later 
date we can look at adding it to the standard library.

http://code.activestate.com/recipes/



-- 
Steven


More information about the Python-ideas mailing list