Commit eb619bb8 authored by Mark Hammond's avatar Mark Hammond

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.
parent 8107ca47
...@@ -43,3 +43,7 @@ except AttributeError: ...@@ -43,3 +43,7 @@ except AttributeError:
if have_thread_state: if have_thread_state:
TestThreadState() TestThreadState()
import threading
t=threading.Thread(target=TestThreadState)
t.start()
...@@ -425,11 +425,10 @@ static void ...@@ -425,11 +425,10 @@ static void
t_bootstrap(void *boot_raw) t_bootstrap(void *boot_raw)
{ {
struct bootstate *boot = (struct bootstate *) boot_raw; struct bootstate *boot = (struct bootstate *) boot_raw;
PyThreadState *tstate; PyGILState_STATE gstate;
PyObject *res; PyObject *res;
tstate = PyThreadState_New(boot->interp); gstate = PyGILState_Ensure();
PyEval_AcquireThread(tstate);
res = PyEval_CallObjectWithKeywords( res = PyEval_CallObjectWithKeywords(
boot->func, boot->args, boot->keyw); boot->func, boot->args, boot->keyw);
if (res == NULL) { if (res == NULL) {
...@@ -454,8 +453,7 @@ t_bootstrap(void *boot_raw) ...@@ -454,8 +453,7 @@ t_bootstrap(void *boot_raw)
Py_DECREF(boot->args); Py_DECREF(boot->args);
Py_XDECREF(boot->keyw); Py_XDECREF(boot->keyw);
PyMem_DEL(boot_raw); PyMem_DEL(boot_raw);
PyThreadState_Clear(tstate); PyGILState_Release(gstate);
PyThreadState_DeleteCurrent();
PyThread_exit_thread(); PyThread_exit_thread();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment