Skip to content

Commit abd66f1

Browse files
authored
lso stop tracemalloc when using exec_with_profiler on Py2
1 parent 64c8199 commit abd66f1

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

memory_profiler.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,17 +1123,17 @@ def exec_with_profiler(filename, profiler, backend, passed_args=[]):
11231123
ns = dict(_CLEAN_GLOBALS, profile=profiler)
11241124
_backend = choose_backend(backend)
11251125
sys.argv = [filename] + passed_args
1126-
if _backend == 'tracemalloc' and has_tracemalloc:
1127-
tracemalloc.start()
1128-
if PY2:
1129-
execfile(filename, ns, ns)
1130-
else:
1131-
try:
1126+
try:
1127+
if _backend == 'tracemalloc' and has_tracemalloc:
1128+
tracemalloc.start()
1129+
if PY2:
1130+
execfile(filename, ns, ns)
1131+
else:
11321132
with open(filename) as f:
11331133
exec(compile(f.read(), filename, 'exec'), ns, ns)
1134-
finally:
1135-
if has_tracemalloc and tracemalloc.is_tracing():
1136-
tracemalloc.stop()
1134+
finally:
1135+
if has_tracemalloc and tracemalloc.is_tracing():
1136+
tracemalloc.stop()
11371137

11381138

11391139
def run_module_with_profiler(module, profiler, backend, passed_args=[]):

0 commit comments

Comments
 (0)