Cython: How to print without GIL

How should I use print in a Cython function with no gil? For example:

from libc.math cimport log, fabs
cpdef double f(double a, double b) nogil:
    cdef double c = log( fabs(a - b) )
    print c
    return c

gives this error when compiling:

Error compiling Cython file:
    print c

Python print statement not allowed without gil

I know how to use C libraries instead of their python equivalent (math library for example here) but I couldn't find a similar way for print.

Use printf from stdio:

from libc.stdio cimport printf
printf("%f\n", c)

0 Comment



Captcha image