[Python-Dev] with_traceback (original) (raw)

Adam Olsen rhamph at gmail.com
Wed Feb 28 15:33:35 CET 2007


On 2/27/07, glyph at divmod.com <glyph at divmod.com> wrote:

On Tue, 27 Feb 2007 13:37:21 +1300, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

>I don't like that answer. I can think of legitimate >reasons for wanting to pre-create exceptions, e.g. if >I'm intending to raise and catch a particular exception >frequently and I don't want the overhead of creating >a new instance each time. This seems like kind of a strange micro-optimization to have an impact on a language change discussion. Wouldn't it be better just to optimize instance creation overhead? Or modify new on your particular heavily-optimized exception to have a free-list, so it can be both correct (you can still mutate exceptions) and efficient (you'll only get a new exception object if you really need it).

It sounds like we should always copy the exception given to raise, and that not doing so is an optimization (albeit a commonly hit one).

Not arguing for or against, just making an observation.

On second thought, we could check that the refcount is 1 and avoid copying in the common case of "raise Foo()". Is reraising common enough that we need to optimize it?

-- Adam Olsen, aka Rhamphoryncus



More information about the Python-Dev mailing list