From 42172900af06baeee559d33b150d5febdf8e960a Mon Sep 17 00:00:00 2001 From: Chris Laplante Date: Wed, 9 Sep 2020 12:55:30 -0400 Subject: utils: process_profilelog: use context manager Signed-off-by: Chris Laplante Signed-off-by: Richard Purdie --- lib/bb/utils.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/bb/utils.py b/lib/bb/utils.py index e51b8ca50..2d4b258b8 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -1071,21 +1071,20 @@ def process_profilelog(fn, pout = None): # Either call with a list of filenames and set pout or a filename and optionally pout. if not pout: pout = fn + '.processed' - pout = open(pout, 'w') - - import pstats - if isinstance(fn, list): - p = pstats.Stats(*fn, stream=pout) - else: - p = pstats.Stats(fn, stream=pout) - p.sort_stats('time') - p.print_stats() - p.print_callers() - p.sort_stats('cumulative') - p.print_stats() - - pout.flush() - pout.close() + + with open(pout, 'w') as pout: + import pstats + if isinstance(fn, list): + p = pstats.Stats(*fn, stream=pout) + else: + p = pstats.Stats(fn, stream=pout) + p.sort_stats('time') + p.print_stats() + p.print_callers() + p.sort_stats('cumulative') + p.print_stats() + + pout.flush() # # Was present to work around multiprocessing pool bugs in python < 2.7.3 -- cgit 1.2.3-korg