2
試圖編譯以下MCE:用Cython錯誤:強制在Python不允許沒有GIL
from libc.math import fabs
cdef inline double fmax(double x, double y) nogil:
return x if x > y else y
cdef inline double fsign(double x) nogil :
if x == 0.:
return 0.
elif x > 0.:
return 1.
else:
return - 1.
cdef inline double ST(double u, double x) nogil:
return fsign(x) * fmax(fabs(x) - u, 0.)
我得到的,除其他錯誤:
Error compiling Cython file:
------------------------------------------------------------
...
else:
return - 1.
cdef inline double ST(double u, double x) nogil:
return fsign(x) * fmax(fabs(x) - u, 0.)
^
------------------------------------------------------------
test.pyx:18:35: Coercion from Python not allowed without the GIL
我不知道發生了什麼,因爲從我的角度來看,所有的值都是雙倍的(除了可能是0.這可能是一個浮點數,但可以安全地提升爲雙倍)
該setup.py
是:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("*.pyx"),
)
編輯:其實,有很多與該行相關的不同的錯誤,如:
test.pyx:18:35: Operation not allowed without gil
test.pyx:18:31: Calling gil-requiring function not allowed without gil
test.pyx:18:31: Accessing Python global or builtin not allowed without gil
test.pyx:18:33: Converting to Python object not allowed without gil
test.pyx:18:31: Constructing Python tuple not allowed without gil