[Python-bugs-list] [ python-Bugs-467571 ] profile.py mishandles exceptions
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 03 Oct 2001 14:47:16 -0700
Bugs item #467571, was opened at 2001-10-03 10:51
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467571&group_id=5470
Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Stephen A. Langer (slanger)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: profile.py mishandles exceptions
Initial Comment:
The profiler in profile.py does not correctly handle
exceptions raised by Python code and caught in built-in functions. For example, if a class has a __getattr__ function that raises an AttributeError, and that exception is caught by hasattr, the profiler never notices that __getattr__ has returned. This is because it never receives an 'exception' event corresponding to the frame in which the exception was caught. The consequence is that subsequent function calls are attributed to the wrong callers, non-recursive functions may be seen as recursive, and the times reported for functions may be vastly incorrect.
I have attached an example program that demonstrates this. I've checked it with Python 1.5.2, 2.0.1 and 2.1.1 on Intel/Linux2.4, and Python 2.1 on SGI/IRIX6.5.
I have also written a replacement for profile.py and pstats.py, which I'd be glad to contribute once I've documented it a bit better. It runs a bit slower than the original, but it does get the right answers (I believe). How does one go about making submissions to the library?
Thanks.
Steve Langer
National Institute of Standards and Technology
stephen.langer@nist.gov
----------------------------------------------------------------------
>Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-10-03 14:47
Message:
Logged In: YES
user_id=3066
The example code seems to be attached now; thanks!
We're increasingly aware of the problems with the profiler.
We expect to take care of this in the "right way" for
Python 2.2 (by changing the events passed to the profiler)
so that the stack management is reliable. We hope to also
have a working profiler for Python 2.1.x as well, and sooner
rather than later.
----------------------------------------------------------------------
Comment By: Stephen A. Langer (slanger)
Date: 2001-10-03 11:22
Message:
Logged In: YES
user_id=340060
This is my last attempt to attach the sample code... if it
doesn't work, send me mail and I'll send the code.
-- Steve (stephen.langer@nist.gov)
----------------------------------------------------------------------
Comment By: Stephen A. Langer (slanger)
Date: 2001-10-03 11:19
Message:
Logged In: YES
user_id=340060
last time I forgot the little checkbox... do I get an
award for the most empty followups?
----------------------------------------------------------------------
Comment By: Stephen A. Langer (slanger)
Date: 2001-10-03 11:18
Message:
Logged In: YES
user_id=340060
Ok, this is ridiculous... I'll see if a different browser
lets me attach a file.
----------------------------------------------------------------------
Comment By: Stephen A. Langer (slanger)
Date: 2001-10-03 11:14
Message:
Logged In: YES
user_id=340060
Second attempt to attach sample code....
----------------------------------------------------------------------
Comment By: Stephen A. Langer (slanger)
Date: 2001-10-03 11:14
Message:
Logged In: YES
user_id=340060
Second attempt to attach sample code....
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467571&group_id=5470