I’ve encountered the situation when Python is initialized (Py_IsInitialized() returns 1), but _PyRuntime.gilstate.tstate_current is null.
_PyRuntime.gilstate.tstate_current is then used by _PyInterpreterState_GET() in PyModule_Create2. PyModule_Create2 crashes because _PyInterpreterState_GET() returns an invalid pointer because _PyRuntime.gilstate.tstate_current is null. The pybind11 code crashes during module creation because of this problem.
Debugger shows that _PyRuntime.gilstate.tstate_current was changed to null and back to non-null tens of thousands times before the problem occurs.
Is it a valid condition that Python is initialized and _PyRuntime.gilstate.tstate_current is null ?