changeset: 87916:dc4e805ec68a user: Victor Stinner date: Fri Dec 13 01:46:43 2013 +0100 files: Misc/NEWS Python/pystate.c description: 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 -r c1a7ba57b4ff -r dc4e805ec68a Misc/NEWS --- a/Misc/NEWS Thu Dec 12 23:07:40 2013 +0100 +++ b/Misc/NEWS Fri Dec 13 01:46:43 2013 +0100 @@ -10,6 +10,11 @@ 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 -r c1a7ba57b4ff -r dc4e805ec68a Python/pystate.c --- a/Python/pystate.c Thu Dec 12 23:07:40 2013 +0100 +++ b/Python/pystate.c Fri Dec 13 01:46:43 2013 +0100 @@ -771,6 +771,11 @@ 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)