简体   繁体   English

Cython错误:没有GIL就不允许来自Python的强制

[英]Cython error: Coercion from Python not allowed without the GIL

Trying to compile the following MCE: 尝试编译以下MCE:

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.)

I get, amongst other errors: 除其他错误外,我得到了:

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

I have no clue what is happening, since from my point of view all values are double (except may 0. which could be a float, but can safely be promoted to double) 我不知道发生了什么,因为从我的观点来看,所有的值都是双倍的(可能是0,可以是浮点数,但可以安全地提升为double)

The setup.py is: setup.py是:

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules=cythonize("*.pyx"),
)

EDIT : Actually, there are plenty of different errors associated with this line, such as: 编辑 :实际上,这一行有很多不同的错误,例如:

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

这只是“一个错字”,但错误信息并没有帮助我很多,所以我发布这个作为答案:我使用了libc.math import fabs ,而不是cimport fabs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM