It’d be nice if it was documented that this was the same. I recently spent some time looking at the code trying to work out if it was (and came to the conclusion that it probably was but I wasn’t certain).
In general I’m in favour of something close to PyGILState_Ensure
that works with subinterpreters - and specifically the idea that you can nest
state1 = PyGILState_Ensure();
{
Py_BEGIN_ALLOW_THREADS
{
state2 = PyGILState_Ensure();
PyGILState_Release(state2);
}
Py_END_ALLOW_THREADS
}
PyGILState_Release(state1);
and the inner “ensure” will restore the state from the outer one.