Skip to content

Commit 4089e3e

Browse files
authored
Merge pull request #201 from mjpieters/patch-1
Make memory_profiler work with Python 2.7 tracemalloc
2 parents 9530029 + 8e5e27b commit 4089e3e

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

memory_profiler.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
if PY2:
5050
import __builtin__ as builtins
51+
from future_builtins import filter
5152
else:
5253
import builtins
5354

@@ -1122,17 +1123,14 @@ def exec_with_profiler(filename, profiler, backend, passed_args=[]):
11221123
ns = dict(_CLEAN_GLOBALS, profile=profiler)
11231124
_backend = choose_backend(backend)
11241125
sys.argv = [filename] + passed_args
1125-
if PY2:
1126-
execfile(filename, ns, ns)
1127-
else:
1126+
try:
11281127
if _backend == 'tracemalloc' and has_tracemalloc:
11291128
tracemalloc.start()
1130-
try:
1131-
with open(filename) as f:
1132-
exec(compile(f.read(), filename, 'exec'), ns, ns)
1133-
finally:
1134-
if has_tracemalloc and tracemalloc.is_tracing():
1135-
tracemalloc.stop()
1129+
with open(filename) as f:
1130+
exec(compile(f.read(), filename, 'exec'), ns, ns)
1131+
finally:
1132+
if has_tracemalloc and tracemalloc.is_tracing():
1133+
tracemalloc.stop()
11361134

11371135

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

0 commit comments

Comments
 (0)