From: Mark Hammond Date: Tue, 24 Aug 2004 22:24:08 +0000 (+0000) Subject: Fix for [ 1010677 ] thread Module Breaks PyGILState_Ensure(), X-Git-Tag: v2.4a3~135 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb619bb80b651a99abd1fe016d0ac024cbd9677a;p=python Fix for [ 1010677 ] thread Module Breaks PyGILState_Ensure(), and a test case. When booting a new thread, use the PyGILState API to manage the GIL. --- diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py index 82bded41cf..bda706a395 100644 --- a/Lib/test/test_capi.py +++ b/Lib/test/test_capi.py @@ -43,3 +43,7 @@ except AttributeError: if have_thread_state: TestThreadState() + import threading + t=threading.Thread(target=TestThreadState) + t.start() + diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c index b398a25d89..cba01faf06 100644 --- a/Modules/threadmodule.c +++ b/Modules/threadmodule.c @@ -425,11 +425,10 @@ static void t_bootstrap(void *boot_raw) { struct bootstate *boot = (struct bootstate *) boot_raw; - PyThreadState *tstate; + PyGILState_STATE gstate; PyObject *res; - tstate = PyThreadState_New(boot->interp); - PyEval_AcquireThread(tstate); + gstate = PyGILState_Ensure(); res = PyEval_CallObjectWithKeywords( boot->func, boot->args, boot->keyw); if (res == NULL) { @@ -454,8 +453,7 @@ t_bootstrap(void *boot_raw) Py_DECREF(boot->args); Py_XDECREF(boot->keyw); PyMem_DEL(boot_raw); - PyThreadState_Clear(tstate); - PyThreadState_DeleteCurrent(); + PyGILState_Release(gstate); PyThread_exit_thread(); }