简体   繁体   English

在没有 GIL 的情况下不允许来自 Python 的强制,并行使用 arrays(Cython 中的多线程)

[英]Coercion from Python not allowed without the GIL, using arrays in parallel (multithreading in Cython)

void worker(int *P,int l):
  cdef i

  with nogil, parallel():
    for i in prange(l):
        P[i]=1

I'm trying to use arrays in cython with multithreading.. but i get this error:我正在尝试在具有多线程的 cython 中使用 arrays .. 但我收到此错误:

Coercion from Python not allowed without the GIL没有 GIL 就不允许来自 Python 的强制

the array P is initialized like this:数组 P 的初始化如下:

cdef int l=500000

cdef int *P=<int *> malloc(l* sizeof(int))

any help?有什么帮助吗?

If you don't specify a type (eg cdef i ) then i is a Python object.如果您不指定类型(例如cdef i ),则i是 Python object。 Therefore you are not allowed to use i within a nogil block.因此,您不允许在nogil块中使用i You probably want cdef int i or similar to specify that i is a C integer.您可能希望cdef int i或类似的指定i是 C integer。

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

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