GIL release after sub-interpreter destruction

I am implementing Python 3.2 in a C ++ application, and I have several sub-interpreters that run at different times in programs (created Py_NewInterpreter). They acquire and release GIL at different times, but I have a problem when I want to destroy one of the sub-translators.

To destroy a sub-interpreter, you must acquire a GIL. So I do this:

PyEval_AcquireLock(threadstate);

Then I destroy the interpreter with

Py_EndInterpreter(threadstate);

And you think that he will release the GIL, because the thing that held him was destroyed. However, the documentation for Py_EndInterpreterstates:

This thread state should be the current thread state. See the discussion of thread states below. When the call returns, the current state of the stream is NULL. (The global lock of the interpreter must be saved before calling this function and saved when it returns.)

So, if I need to hold the GIL when I destroy the sub-interpreter and destroy the sub-interpreter, it sets it to NULL, and I must have the thread that acquired the GIL in order to free it, how can I free the GIL after destroying the sub- interpreter?

+3
source share
1 answer

What happens if you call PyEval_ReleaseLock()immediately after the call Py_EndInterpreter()? This is what the docs tell you to do anyway. :)

+2
source

All Articles