Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove python assertion when compiling in cython?

so, here is my problem: I code in python, but I need to improve performance in some part of my code that are too slow. A good(and easy) solution seems to be using cython; I tried it and got good results. The issue is that I use assert statement in my python code. Before using cython, I could compile my python code with the -OO option, so that I can deliver a version not executing any assertion test, and still have the assert for debug. But the files that are compiled in cython seems to always execute the asserts. Is there some options that can be passed to cython compilation to remove(or not remove) the assertions?

like image 571
user521353 Avatar asked Nov 26 '10 12:11

user521353


1 Answers

Cython skips the assertions if you define the C preprocessor macro PYREX_WITHOUT_ASSERTIONS. So pass -DPYREX_WITHOUT_ASSERTIONS to the C compiler when compiling the generated C file. How to to this depends on your build process.

like image 190
Sven Marnach Avatar answered Sep 28 '22 06:09

Sven Marnach