rkern / line_profiler

(OLD REPO) Line-by-line profiling for Python - Current repo ->
https://github.com/pyutils/line_profiler
Other
3.6k stars 256 forks source link

Python 3 attempting to view lprof file. #170

Open bobhancock opened 4 years ago

bobhancock commented 4 years ago

Cmd Line: kernprof -v ./simply.py.lprof

Some of the report is displayed and then this staacktrace below. I inserted a pdb.set_trace() in kernprof.py and the filename is correct and the file handle also.

Traceback (most recent call last): File "/usr/bin/kernprof", line 11, in load_entry_point('line-profiler==2.1.1', 'consolescripts', 'kernprof')() File "/usr/local/google/home/rwh/.local/lib/python3.7/site-packages/kernprof.py", line 226, in main prof.runctx('execfile(%r, globals())' % (script_file,), ns, ns) File "/usr/local/google/home/rwh/python/src/pyenv/versions/3.7.0/lib/python3.7/cProfile.py", line 100, in runctx exec(cmd, globals, locals) File "", line 1, in File "/usr/local/google/home/rwh/.local/lib/python3.7/site-packages/kernprof.py", line 36, in execfile with open(filename, 'rb') as f: ValueError: source code string cannot contain null bytes

try: execfile except NameError:

Python 3.x doesn't have 'execfile' builtin

import builtins
exec_ = getattr(builtins, "exec")

def execfile(filename, globals=None, locals=None):
   pdb.set_trace()
    with open(filename, 'rb') as f:
        exec_(compile(f.read(), filename, 'exec'), globals, locals)
tharwan commented 4 years ago

same here.