From: Victor Stinner Date: Fri, 13 Dec 2013 00:46:43 +0000 (+0100) Subject: Close #19576: PyGILState_Ensure() now initializes threads. At startup, Python X-Git-Tag: v3.4.0b2~246 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=62ca10051b5aa07b86807a50674dbef4cace22f7;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Misc/NEWS b/Misc/NEWS index 2c1df0943ce3..84f36b8fee0a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ Release date: 2014-01-05 Core and Builtins ----------------- +- Issue #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. + - Issue #17576: Deprecation warning emitted now when __int__() or __index__() return not int instance. diff --git a/Python/pystate.c b/Python/pystate.c index 6be71de2ae0b..a56e3089694e 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -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)