Exception raising, and performance implications.

Tony Nelson *firstname*nlsnews at georgea*lastname*.com
Mon Oct 3 18:03:28 EDT 2005


In article <1128375280.034852.119910 at o13g2000cwo.googlegroups.com>,
 "leo" <leomendoza at gmail.com> wrote:

> Hello all -
> 
> I was wondering about the performance implications of explicitly
> raising exceptions to get information about the current frame.
> Something like what the inspect module does, with:

Python uses exceptions internally, using StopIteration to terminate the 
iterator in a for: loop.

> ---
> def currentframe():
>     """Return the frame object for the caller's stack frame."""
>     try:
>         raise 'catch me'
>     except:
>         return sys.exc_traceback.tb_frame.f_back
> ---

This also does a traceback; you might want to measure the cost of that.

> I come from a java background, where Exceptions are a big Avoid Me, but
> are the performance implications the same in Python? We're expecting a
> big load on our app (100,000 users/hour) , so we'd like to be as tuned
> as possible.

Switching to Python, eh?  Remember to measure, measure, measure!
________________________________________________________________________
TonyN.:'                        *firstname*nlsnews at georgea*lastname*.com
      '                                  <http://www.georgeanelson.com/>



More information about the Python-list mailing list