Open mathijsmeulendijks opened 4 years ago
Related SO question.
Workaround (as mentioned above):
cpdef my_cython_function():
x = 0
for i in range(100):
x += i**2
return x
def this_function_causes_line_profiler_to_print_all_the_way_down_here():
pass
When profiling a Cython cpdef function, LineProfiler.print_stats() only shows timings for the function definition line instead of line-by-line.
Expected behavior
Observed behavior
Details
LineProfiler.show_func uses
inspect.getblock
to get the lines of the profiled function. This doesn't work for cpdef functions. Python 3.75 on Windows line_profiler 3.0.2Workaround
In the .pyx file, add a
def
(no cdef or cpdef) function at the end of the file.Possible solution
Use an alternative for
inspect.getblock