罗伯特·布拉德肖(Robert Bradshaw)帮助我获得了罗伯特·克恩(Robert
Kern)的
line_profiler工具用于
cdef函数的工作,我认为我会在上分享结果
stackoverflow。
简而言之,请设置常规
.pyx文件并生成脚本,并在调用之前添加以下内容
cythonize。
# Thanks to @tryptofame for proposing an updated snippetfrom Cython.Compiler.Options import get_directive_defaultsdirective_defaults = get_directive_defaults()directive_defaults['linetrace'] = Truedirective_defaults['binding'] = True
此外,您需要
CYTHON_TRACE=1通过修改
extensions设置来定义C宏,以便
extensions = [ Extension("test", ["test.pyx"], define_macros=[('CYTHON_TRACE', '1')])]%%cython在
iPython笔记本中使用魔术的一个有效示例在此处:http
:
//nbviewer.ipython.org/gist/tillahoffmann/296501acea231cbdf5e7



