나는 Cython을 통해 파이썬에 접근 할 수있게 해주는 std :: thread를 사용하는 몇 가지 메소드를 가진 C++ 클래스를 가지고있다. 내 Cython 코드에서 nogill 지시문을 어디에 넣고 싶습니까? 클래스 메서드를 선언 할 때 또는 Cython 래퍼 클래스를 만들 때 넣을 수 있습니까?다중 스레드 C++ 클래스에 대해 Cython에서 GIL을 해제하는 방법은 무엇입니까?
이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)
사이 썬 래퍼 클래스 :
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)