homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gdr@garethrees.org
Recipients gdr@garethrees.org
Date 2011年07月07日.14:58:52
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1310050733.66.0.963908910352.issue12514@psf.upfronthosting.co.za>
In-reply-to
Content
If you call timeit.timeit and the timed code raises an exception, then garbage collection is disabled. I have verified this in Python 2.7 and 3.2. Here's an interaction with Python 3.2:
 Python 3.2 (r32:88445, Jul 7 2011, 15:52:49) 
 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import timeit, gc
 >>> gc.isenabled()
 True
 >>> timeit.timeit('raise Exception')
 Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/timeit.py", line 228, in timeit
 return Timer(stmt, setup, timer).timeit(number)
 File "/opt/local/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/timeit.py", line 194, in timeit
 timing = self.inner(it, self.timer)
 File "<timeit-src>", line 6, in inner
 Exception
 >>> gc.isenabled()
 False
The problem is with the following code in Lib/timeit.py (lines 192–196):
 gcold = gc.isenabled()
 gc.disable()
 timing = self.inner(it, self.timer)
 if gcold:
 gc.enable()
This should be changed to something like this:
 gcold = gc.isenabled()
 gc.disable()
 try:
 timing = self.inner(it, self.timer)
 finally:
 if gcold:
 gc.enable()
History
Date User Action Args
2011年07月07日 14:58:53gdr@garethrees.orgsetrecipients: + gdr@garethrees.org
2011年07月07日 14:58:53gdr@garethrees.orgsetmessageid: <1310050733.66.0.963908910352.issue12514@psf.upfronthosting.co.za>
2011年07月07日 14:58:52gdr@garethrees.orglinkissue12514 messages
2011年07月07日 14:58:52gdr@garethrees.orgcreate

AltStyle によって変換されたページ (->オリジナル) /