diff -r 0741add59487 Lib/cProfile.py --- a/Lib/cProfile.py Mon Mar 19 13:17:24 2012 +0100 +++ b/Lib/cProfile.py Tue Mar 20 22:26:15 2012 +0800 @@ -45,10 +45,9 @@ prof = Profile() result = None try: - try: - prof = prof.runctx(statement, globals, locals) - except SystemExit: - pass + prof = prof.runctx(statement, globals, locals) + except SystemExit: + pass finally: if filename is not None: prof.dump_stats(filename) diff -r 0741add59487 Lib/profile.py --- a/Lib/profile.py Mon Mar 19 13:17:24 2012 +0100 +++ b/Lib/profile.py Tue Mar 20 22:26:15 2012 +0800 @@ -77,11 +77,11 @@ prof = prof.runctx(statement, globals, locals) except SystemExit: pass - - if filename is not None: - prof.dump_stats(filename) - else: - return prof.print_stats(sort) + finally: + if filename is not None: + prof.dump_stats(filename) + else: + return prof.print_stats(sort) if hasattr(os, "times"): def _get_time_times(timer=os.times):