rkern / line_profiler

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

UserWarning: Could not extract a code object for the object XXX - Simple example #125

Closed SebastianoF closed 6 years ago

SebastianoF commented 6 years ago

Hi, Here is the issue:

In an Ipython session

%load_ext line_profiler
def fibo_iter(N):
    a, b = 0, 1
    for _ in range(N):
        a, b = b, a + b
    return b

%lprun -f fibo_iter  # works with empty columns

Returns:

Timer unit: 1e-06 s

Total time: 0 s
File: <ipython-input-24-0e7d3bd476c9>
Function: fibo_iter at line 1

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
     1                                           def fibo_iter(N):
     2                                               a, b = 0, 1
     3                                               for _ in range(N):
     4                                                   a, b = b, a + b

If an argument is passed:

%lprun -f fibo_iter(10) 

It raises the warning, returning:

/Applications/python_virtualenvs/clean3/lib/python3.6/site-packages/line_profiler.py:321: UserWarning: Could not extract a code object for the object 89
  profile = LineProfiler(*funcs)
Timer unit: 1e-06 s

Any idea? Probably I am doing something very stupid here...

justinmoon commented 6 years ago

This is a duplicate of https://github.com/rkern/line_profiler/issues/94, which has a workaround.

Note: both issues filed on same day ...

SebastianoF commented 6 years ago

Thanks! Interesting the "samedayness". I guess this is the more likely condition for duplicates to happen. Close the issue here. If someone may need to re-open, please use #94.