]> granicus.if.org Git - python/commitdiff
#1019882: if start() and stop() were not in the same stack frame, stats.load() would...
authorGeorg Brandl <georg@python.org>
Sat, 31 Jul 2010 21:22:36 +0000 (21:22 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 31 Jul 2010 21:22:36 +0000 (21:22 +0000)
Lib/hotshot/log.py
Lib/test/test_hotshot.py
Misc/NEWS

index 47c932ac2dae2e9ca0ef8cb91ee03cf2b857463e..17e8b50515af32707fcd91e7ac6590d70c09d33d 100644 (file)
@@ -106,7 +106,10 @@ class LogReader:
                 return what, t, tdelta
 
             if what == WHAT_EXIT:
-                return what, self._pop(), tdelta
+                try:
+                    return what, self._pop(), tdelta
+                except IndexError:
+                    raise StopIteration
 
             if what == WHAT_LINENO:
                 filename, firstlineno, funcname = self._stack[-1]
index c6dae363cdcb90ed29642e7dacb90ebc9b873bf5..7da9746d789e2e3e55f0a28dea4c65b58217d921 100644 (file)
@@ -10,6 +10,7 @@ from test import test_support
 # Silence Py3k warning
 hotshot = test_support.import_module('hotshot', deprecated=True)
 from hotshot.log import ENTER, EXIT, LINE
+from hotshot import stats
 
 
 def shortfilename(fn):
@@ -136,6 +137,19 @@ class HotShotTestCase(unittest.TestCase):
             emptyfile.close()
         gc.collect()
 
+    def test_load_stats(self):
+        def start(prof):
+            prof.start()
+        # Make sure stats can be loaded when start and stop of profiler
+        # are not executed in the same stack frame.
+        profiler = self.new_profiler()
+        start(profiler)
+        profiler.stop()
+        profiler.close()
+        stats.load(self.logfn)
+        os.unlink(self.logfn)
+
+
 def test_main():
     test_support.run_unittest(HotShotTestCase)
 
index fed077297b92045fd031af08fb7a3d440dd6790c..ea60e3b818d25719075015f713a294f8d8b6c444 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -64,6 +64,8 @@ Library
 Extension Modules
 -----------------
 
+- Issue #1019882: Fix IndexError when loading certain hotshot stats.
+
 - Issue #9422: Fix memory leak when re-initializing a struct.Struct object.
 
 - Issue #7900: The getgroups(2) system call on MacOSX behaves rather oddly