Cannot use line_profiler with Cython

醉酒当歌 提交于 2019-12-05 07:11:22

The profile decorator is injected into the globals namespace by kernprof and is thus not available at compile time. However, you can apply the profile decorator to a function even after it has been defined. For example, in your script.py you could write the following.

from cython_module import function_to_be_profiled
# Apply the `profile` decorator
function_to_be_profiled = profile(function_to_be_profiled)

# Use function_to_be_profiled as intended

The third line of the snippet will fail if you run the script using standard python, i.e. python script.py, because the profile decorator is not defined. But it should behave as intended if you run it using kernprof.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!