Skip to content

Commit 8e5e27b

Browse files
authored
Correctly handle try/except in exec_with_profiler
Do away with the PY2 distinction altogether; Python 2 supports the same `exec()` pattern. Now the `try:...finally:` block properly applies in both 2 and 3.
1 parent abd66f1 commit 8e5e27b

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

memory_profiler.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,11 +1126,8 @@ def exec_with_profiler(filename, profiler, backend, passed_args=[]):
11261126
try:
11271127
if _backend == 'tracemalloc' and has_tracemalloc:
11281128
tracemalloc.start()
1129-
if PY2:
1130-
execfile(filename, ns, ns)
1131-
else:
1132-
with open(filename) as f:
1133-
exec(compile(f.read(), filename, 'exec'), ns, ns)
1129+
with open(filename) as f:
1130+
exec(compile(f.read(), filename, 'exec'), ns, ns)
11341131
finally:
11351132
if has_tracemalloc and tracemalloc.is_tracing():
11361133
tracemalloc.stop()

0 commit comments

Comments
 (0)