Cython prange 因致命 Python 错误而失败:PyThreadState_Get:没有当前线程

Posted

技术标签:

【中文标题】Cython prange 因致命 Python 错误而失败:PyThreadState_Get:没有当前线程【英文标题】:Cython prange fails with Fatal Python error: PyThreadState_Get: no current thread 【发布时间】:2017-02-09 08:50:51 【问题描述】:

我正在尝试使用 prange 并行化循环:

cdef fun(double [::1] someData)) nogil:
    #direct call to a external c function
    C_function(&someData[0])

#....
def parallelEvaluate(np.ndarray[np.double_t] largerArray):
    #....
    cdef np.ndarray[np.double_t] array
    cdef np.ndarray[np.int] arbitraryIndices
    for n in prange(loopLength, nogil=true):
        with gil:
            arbitraryIndices = # ... indices dependent on n
            array = np.copy( largerArray[ arbitraryIndices]  ) # copy of a non cont. array to the cont. 'array'
        fun(array)

但是,这失败了: 致命的 Python 错误:PyThreadState_Get:没有当前线程

这种行为的原因是什么?

谢谢!

【问题讨论】:

有几个问题有类似的错误(例如***.com/questions/35640529/…),它们暗示您可能已将不同的 Python 库链接到您使用的库。 【参考方案1】:

好吧,想通了:

从 np.ndarray 的隐式转换不起作用;我用一个额外的 memoryview 切片解决了它。

【讨论】:

以上是关于Cython prange 因致命 Python 错误而失败:PyThreadState_Get:没有当前线程的主要内容,如果未能解决你的问题,请参考以下文章