Skip to content

Commit 64c8199

Browse files
authored
Make memory_profiler work with Python 2.7 tracemalloc
The tracemalloc module can be made to work on Python 2.7 with [the project providing patches against the Pyithon 2.7 source code](http://pytracemalloc.readthedocs.io/install.html#manual-installation). These two changes make `memory_profiler.py` work with tracemalloc on Python 2.
1 parent 9530029 commit 64c8199

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

memory_profiler.py

Lines changed: 3 additions & 2 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,11 +1123,11 @@ 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
1126+
if _backend == 'tracemalloc' and has_tracemalloc:
1127+
tracemalloc.start()
11251128
if PY2:
11261129
execfile(filename, ns, ns)
11271130
else:
1128-
if _backend == 'tracemalloc' and has_tracemalloc:
1129-
tracemalloc.start()
11301131
try:
11311132
with open(filename) as f:
11321133
exec(compile(f.read(), filename, 'exec'), ns, ns)

0 commit comments

Comments
 (0)