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

I read Cython debugging, set a breakpoint and https://groups.google.com/forum/#!topic/apam-python-users/6rsRwcCAms4 and I wonder what is the best workflow when debugging cython code that is called from python code?

Ideally, I would like to go into .pyx files during a python debugging session initiated with my IDE (pycharm), but this seems to be impossible. Is it not possible to compile debugging information when pyx files are drawn in cython so that the debugger can intervene?

If this cannot be achieved, what are the alternatives (other than using cython!)?

This question specifically asks how to get into cython code, although it is similar to Cython and Python Project Test Driven Development and .pyx file structure advice , this is not the same.

+5
source share
2 answers

The official path seems to be your best option. It would be great if there was a simple alternative, but from the link you included here , it seems not. This wiki document seems to contain some additional tips that are missing from the white paper.

+2
source

If you use Cython only for speed (i.e. not for packaging C libraries), you can use pure Python mode , which allows you to define types either in a separate .pxd file (which exists next to your code in the .py file), either using decorators.

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

Otherwise, your best bet would be the traditional "multitude of print applications." print locals() can be useful here! However, this is not entirely satisfactory.

+2
source

Source: https://habr.com/ru/post/1232716/


All Articles