【问题标题】:Coercion from Python not allowed without the GIL, using arrays in parallel (multithreading in Cython)没有 GIL 就不允许来自 Python 的强制,并行使用数组(Cython 中的多线程)
【发布时间】:2020-12-27 01:11:17
【问题描述】:
void worker(int *P,int l):
  cdef i

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

我正在尝试在 cython 中使用具有多线程的数组.. 但我收到此错误:

没有 GIL 就不允许来自 Python 的强制

数组 P 的初始化如下:

cdef int l=500000

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

有什么帮助吗?

【问题讨论】:

    标签: python arrays multithreading cython


    【解决方案1】:

    如果您不指定类型(例如cdef i),则i 是一个 Python 对象。因此,您不能在 nogil 块内使用 i。您可能希望cdef int i 或类似名称指定i 是一个C 整数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      • 2012-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      相关资源
      最近更新 更多