Skip to content

bpo-39877: Remove useless PyEval_InitThreads() calls #18883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx(struct _frame *f, int exc);
WARNING: NEVER NEST CALLS TO Py_BEGIN_ALLOW_THREADS AND
Py_END_ALLOW_THREADS!!!

The function PyEval_InitThreads() should be called only from
init_thread() in "_threadmodule.c".

Note that not yet all candidates have been converted to use this
mechanism!
*/
Expand Down
5 changes: 2 additions & 3 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ def test_pre_initialization_sys_options(self):

def test_bpo20891(self):
"""
bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
call PyEval_InitThreads() for us in this case.
bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not
crash.
"""
out, err = self.run_embedded_interpreter("test_bpo20891")
self.assertEqual(out, '')
Expand Down
1 change: 0 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5695,7 +5695,6 @@ PyInit__ctypes(void)
ob_type is the metatype (the 'type'), defaults to PyType_Type,
tp_base is the base type, defaults to 'object' aka PyBaseObject_Type.
*/
PyEval_InitThreads();
m = PyModule_Create(&_ctypesmodule);
if (!m)
return NULL;
Expand Down
1 change: 0 additions & 1 deletion Modules/_ctypes/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ static void LoadPython(void)
{
if (!Py_IsInitialized()) {
Py_Initialize();
PyEval_InitThreads();
}
}

Expand Down
4 changes: 0 additions & 4 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,8 +2728,6 @@ test_thread_state(PyObject *self, PyObject *args)
return NULL;
}

/* Ensure Python is set up for threading */
PyEval_InitThreads();
thread_done = PyThread_allocate_lock();
if (thread_done == NULL)
return PyErr_NoMemory();
Expand Down Expand Up @@ -4175,8 +4173,6 @@ call_in_temporary_c_thread(PyObject *self, PyObject *callback)
test_c_thread_t test_c_thread;
long thread;

PyEval_InitThreads();

test_c_thread.start_event = PyThread_allocate_lock();
test_c_thread.exit_event = PyThread_allocate_lock();
test_c_thread.callback = NULL;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
Py_INCREF(func);
Py_INCREF(args);
Py_XINCREF(keyw);
PyEval_InitThreads(); /* Start the interpreter's thread-awareness */

ident = PyThread_start_new_thread(t_bootstrap, (void*) boot);
if (ident == PYTHREAD_INVALID_THREAD_ID) {
PyErr_SetString(ThreadError, "can't start new thread");
Expand Down
6 changes: 2 additions & 4 deletions Programs/_testembed.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static int test_repeated_init_and_subinterpreters(void)
_testembed_Py_Initialize();
mainstate = PyThreadState_Get();

PyEval_InitThreads();
PyEval_ReleaseThread(mainstate);

gilstate = PyGILState_Ensure();
Expand Down Expand Up @@ -252,9 +251,8 @@ static int test_bpo20891(void)
/* the test doesn't support custom memory allocators */
putenv("PYTHONMALLOC=");

/* bpo-20891: Calling PyGILState_Ensure in a non-Python thread before
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
call PyEval_InitThreads() for us in this case. */
/* bpo-20891: Calling PyGILState_Ensure in a non-Python thread must not
crash. */
PyThread_type_lock lock = PyThread_allocate_lock();
if (!lock) {
fprintf(stderr, "PyThread_allocate_lock failed!");
Expand Down
6 changes: 2 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
_PyRuntimeState *runtime = tstate->interp->runtime;
struct _ceval_runtime_state *ceval = &runtime->ceval;

/* Check someone has called PyEval_InitThreads() to create the lock */
/* Check that _PyEval_InitThreads() was called to create the lock */
assert(gil_created(&ceval->gil));

take_gil(ceval, tstate);
Expand Down Expand Up @@ -541,9 +541,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
static int
handle_signals(_PyRuntimeState *runtime)
{
/* Only handle signals on main thread. PyEval_InitThreads must
* have been called already.
*/
/* Only handle signals on main thread */
if (PyThread_get_thread_ident() != runtime->main_thread) {
return 0;
}
Expand Down