Skip to content

Commit e3fc5ee

Browse files
authored
Merge pull request #230 from Ricocotam/master
Fixing #196
2 parents 2c77549 + 6b55898 commit e3fc5ee

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

memory_profiler.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,15 @@ def choose_backend(new_backend=None):
11191119
def exec_with_profiler(filename, profiler, backend, passed_args=[]):
11201120
from runpy import run_module
11211121
builtins.__dict__['profile'] = profiler
1122-
ns = dict(_CLEAN_GLOBALS, profile=profiler)
1122+
ns = dict(_CLEAN_GLOBALS,
1123+
profile=profiler,
1124+
# Make sure the __file__ variable is usable
1125+
# by the script we're profiling
1126+
__file__=filename)
1127+
# Make sure the script's directory in on sys.path
1128+
# credit to line_profiler
1129+
sys.path.insert(0, os.path.dirname(script_filename))
1130+
11231131
_backend = choose_backend(backend)
11241132
sys.argv = [filename] + passed_args
11251133
try:

0 commit comments

Comments
 (0)