Cython:如何不使用GIL进行打印 [英] Cython: How to print without GIL
本文介绍了Cython:如何不使用GIL进行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在没有gil的Cython函数中,如何使用 print
?例如:
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
在编译时给出此错误:
Error compiling Cython file:
...
print c
^
------------------------------------------------------------
Python print statement not allowed without gil
...
我知道如何使用C库而不是等效的python(数学
库),但找不到 print
的类似方法。
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
.
推荐答案
使用 stdio中的
: printf
Use printf
from stdio
:
from libc.stdio cimport printf
...
printf("%f\n", c)
这篇关于Cython:如何不使用GIL进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文