You can define NDEBUG in the setup.py file. Just use the undef_macros parameter when defining the extension:
extensions = [ Extension ( "myprog", [ mysrc.c ], undef_macros = [ "NDEBUG" ] ) ]
In the output of the assembly, you will see -DNDEBUG followed by -UNDEBUG, which overrides it. See the distutils documentation for more information on extension options.
Note, however, that a statement initiated in the extension module will lead to the exit of the python or ipython interpreter.
source share