summaryrefslogtreecommitdiffstats
path: root/Lib/timeit.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-07-29 07:02:04 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-07-29 07:02:04 (GMT)
commit3a081f526d1556129facd38a1bb6a1b8af3abbe7 (patch)
tree8371abaaf2caa7bcc9c208bbd8cd9cb0792e272a /Lib/timeit.py
parentef4902af879cd571e3b57d745c355f255daa09af (diff)
downloadcpython-3a081f526d1556129facd38a1bb6a1b8af3abbe7.zip
cpython-3a081f526d1556129facd38a1bb6a1b8af3abbe7.tar.gz
cpython-3a081f526d1556129facd38a1bb6a1b8af3abbe7.tar.bz2
Issue 12514: Use try/finally to assure that timeit restores GC when done.
Diffstat (limited to 'Lib/timeit.py')
-rw-r--r--Lib/timeit.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/timeit.py b/Lib/timeit.py
index 8e04645..461c891 100644
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -191,9 +191,11 @@ class Timer:
it = [None] * number
gcold = gc.isenabled()
gc.disable()
- timing = self.inner(it, self.timer)
- if gcold:
- gc.enable()
+ try:
+ timing = self.inner(it, self.timer)
+ finally:
+ if gcold:
+ gc.enable()
return timing
def repeat(self, repeat=default_repeat, number=default_number):