aaa8788
aaa8788

Reputation: 1

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:

Coercion from Python not allowed without the GIL

the array P is initialized like this:

cdef int l=500000

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

any help?

Upvotes: 0

Views: 156

Answers (1)

DavidW
DavidW

Reputation: 30910

If you don't specify a type (e.g. cdef i) then i is a Python object. Therefore you are not allowed to use i within a nogil block. You probably want cdef int i or similar to specify that i is a C integer.

Upvotes: 1

Related Questions