Close #19576: PyGILState_Ensure() now initializes threads. At startup, Python

has no concrete GIL. If PyGILState_Ensure() is called from a new thread for the
first time and PyEval_InitThreads() was not called yet, a GIL needs to be
created.
This commit is contained in:
Victor Stinner 2013-12-13 01:46:43 +01:00
parent 56668dc187
commit 62ca10051b
2 changed files with 10 additions and 0 deletions

View file

@ -771,6 +771,11 @@ PyGILState_Ensure(void)
assert(autoInterpreterState); /* Py_Initialize() hasn't been called! */
tcur = (PyThreadState *)PyThread_get_key_value(autoTLSkey);
if (tcur == NULL) {
/* At startup, Python has no concrete GIL. If PyGILState_Ensure() is
called from a new thread for the first time, we need the create the
GIL. */
PyEval_InitThreads();
/* Create a new thread state for this thread */
tcur = PyThreadState_New(autoInterpreterState);
if (tcur == NULL)