summaryrefslogtreecommitdiff
path: root/Lib/pstats.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-22 06:35:59 +0000
committerGeorg Brandl <georg@python.org>2010-10-22 06:35:59 +0000
commit9a8439d3e96fc4779d40628b2d286824de43aa89 (patch)
treedc8cee379d560546c5e60aed73e254488e5e1794 /Lib/pstats.py
parenteb7e56922ef57b38c27d45cff016167fce468d14 (diff)
downloadcpython-git-9a8439d3e96fc4779d40628b2d286824de43aa89.tar.gz
Refactor interesting use of try-finally.
Diffstat (limited to 'Lib/pstats.py')
-rw-r--r--Lib/pstats.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/pstats.py b/Lib/pstats.py
index 321d2684ac..17d727905f 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -93,15 +93,12 @@ class Stats:
self.stats = {}
self.sort_arg_dict = {}
self.load_stats(arg)
- trouble = 1
try:
self.get_top_level_stats()
- trouble = 0
- finally:
- if trouble:
- print("Invalid timing data", end=' ', file=self.stream)
- if self.files: print(self.files[-1], end=' ', file=self.stream)
- print(file=self.stream)
+ except Exception:
+ print("Invalid timing data %s" %
+ (self.files[-1] if self.files else ''), file=self.stream)
+ raise
def load_stats(self, arg):
if arg is None:
@@ -271,7 +268,8 @@ class Stats:
return self
def calc_callees(self):
- if self.all_callees: return
+ if self.all_callees:
+ return
self.all_callees = all_callees = {}
for func, (cc, nc, tt, ct, callers) in self.stats.items():
if not func in all_callees:
@@ -341,7 +339,8 @@ class Stats:
def print_stats(self, *amount):
for filename in self.files:
print(filename, file=self.stream)
- if self.files: print(file=self.stream)
+ if self.files:
+ print(file=self.stream)
indent = ' ' * 8
for func in self.top_level:
print(indent, func_get_function_name(func), file=self.stream)
@@ -427,7 +426,7 @@ class Stats:
print(' ncalls tottime percall cumtime percall', end=' ', file=self.stream)
print('filename:lineno(function)', file=self.stream)
- def print_line(self, func): # hack : should print percentages
+ def print_line(self, func): # hack: should print percentages
cc, nc, tt, ct, callers = self.stats[func]
c = str(nc)
if nc != cc: