【发布时间】:2017-08-03 10:37:36
【问题描述】:
我有一个 C++ 类,其中包含一些使用 std::thread 的方法,我通过 Cython 使 Python 可以访问这些方法。你知道我想在我的 Cython 代码中的哪个位置放置 nogill 指令吗?当我声明类方法或创建 Cython 包装器类时,我想放它吗?我使用了下面 Cython 文档中的示例类:
声明类:
cdef extern from "Rectangle.h" namespace "shapes":
cdef cppclass Rectangle:
Rectangle() except +
Rectangle(int, int, int, int) except +
int x0, y0, x1, y1
int getArea()
void getSize(int* width, int* height)
void move(int, int)
Cython 包装类:
cdef class PyRectangle:
cdef Rectangle c_rect # hold a C++ instance which we're wrapping
def __cinit__(self, int x0, int y0, int x1, int y1):
self.c_rect = Rectangle(x0, y0, x1, y1)
def get_area(self):
return self.c_rect.getArea()
def get_size(self):
cdef int width, height
self.c_rect.getSize(&width, &height)
return width, height
def move(self, dx, dy):
self.c_rect.move(dx, dy)
【问题讨论】:
标签: python c++ multithreading cython gil