]> granicus.if.org Git - python/commitdiff
Fix for [ 1010677 ] thread Module Breaks PyGILState_Ensure(),
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 24 Aug 2004 22:24:08 +0000 (22:24 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Tue, 24 Aug 2004 22:24:08 +0000 (22:24 +0000)
and a test case.
When booting a new thread, use the PyGILState API to manage the GIL.

Lib/test/test_capi.py
Modules/threadmodule.c

index 82bded41cfcba47cf20b2e7d98017a95a9500db9..bda706a3950930bc8ab1d0638fbdf16a9da60119 100644 (file)
@@ -43,3 +43,7 @@ except AttributeError:
 
 if have_thread_state:
     TestThreadState()
+    import threading
+    t=threading.Thread(target=TestThreadState)
+    t.start()
+
index b398a25d8941291562759d47a8d6579cc92c01dc..cba01faf06d67ce748e42aa5ff45eb36206d6884 100644 (file)
@@ -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();
 }