diff --git a/include/pybind11/gil.h b/include/pybind11/gil.h index 570a5581..eb72e15e 100644 --- a/include/pybind11/gil.h +++ b/include/pybind11/gil.h @@ -138,6 +138,7 @@ class gil_scoped_acquire { class gil_scoped_release { public: explicit gil_scoped_release(bool disassoc = false) : disassoc(disassoc) { + assert(PyGILState_Check()); // `get_internals()` must be called here unconditionally in order to initialize // `internals.tstate` for subsequent `gil_scoped_acquire` calls. Otherwise, an // initialization race could occur as multiple threads try `gil_scoped_acquire`.