我将Python 3.2嵌入C++应用程序中,并且我有几个子解释程序在程序的不同时间运行(由{{CD1>}创建)。他们在不同的时间获取和释放GIL,但我遇到了一个问题,当我想摧毁其中一个分译员。在
要想摧毁一个助理翻译,你必须获得GIL。所以我这样做:
PyEval_AcquireLock(threadstate);
然后我用
^{pr2}$你会认为它会释放GIL,因为保存它的东西被摧毁了。但是,Py_EndInterpreter
的文档说明:
The given thread state must be the current thread state. See the discussion of thread states below. When the call returns, the current thread state is NULL. (The global interpreter lock must be held before calling this function and is still held when it returns.)
因此,如果我在销毁一个分解释器时必须持有GIL,并且销毁子解释器会将其设置为NULL,并且我必须让获取GIL的线程来释放它,那么在销毁一个子解释器之后,如何释放GIL?在
如果在调用
Py_EndInterpreter()
之后直接调用PyEval_ReleaseLock()
,会发生什么情况?医生告诉你怎么做。:)相关问题 更多 >
编程相关推荐