Debug cython code (.pyx) when using the python debugger (pdb) - Best Practice

后端 未结 2 584
你的背包
你的背包 2021-02-08 20:41

I have read Cython debugging, put a break point, and https://groups.google.com/forum/#!topic/apam-python-users/6rsRwcCAms4 and wondering what the best workflow is when debugging

相关标签:
2条回答
  • 2021-02-08 21:14

    It seems like the official way is your best option. It would be great if there were an easy alternative but from the link you included here it seems like there isn't. This wiki document seems to have a few additional tips that the official doc is missing.

    0 讨论(0)
  • 2021-02-08 21:14

    If you're only using Cython for speed (i.e. not to wrap C libraries) you could use pure Python mode which lets you define the types either in a separate .pxd file (which exists alongside your code in the .py file), or using decorators.

    The advantage of this mode is that your code can run (and be debugged) under plain Python. You're then left with the (hopefully small) class of bugs that are due to the Cython static typing and not your code. The disadvantages are: 1) running your code under plain Python will be slower; 2) the syntax is a little bit messier than the standard Cython syntax; 3) you can't access external C code like this, which is one of the main use-cases for Cython.

    Failing that your best bet is the traditional "lots of print statements". print locals() can be useful here! It isn't entirely satisfactory though.

    0 讨论(0)
提交回复
热议问题