스레드 간의 상호 작용 패턴을 변경하는 것이 좋습니다.
현재 구현은 다음과 같이 작동하는 것 같다 :
PyGILState_Ensure();
result = doDangerousThing(); // this could kill the thread
storeToPythonObject(result);
PyGILState_Release();
변형을, 명백한 :
result = doDangerousThing(); // this could kill the thread
PyGILState_Ensure();
storeToPythonObject(result);
PyGILState_Release();
변형 B는 덜 분명, 아이디어를 [1], [2]를 참조하십시오
/* worker_thread.c */
result = doDangerousThing(); // this could kill the thread
putToLocklessQueue(result, *queue_in_main_thread);
/* main_thread.c */
if (hasItems(my_lockless_queue)) {
PyGILState_Ensure();
while (hasItems(my_lockless_queue)) {
storeToPythonObject(popItem(my_lockless_queue));
}
PyGILState_Release();
// sleep again here
}