Skip to content

Commit 4894922

Browse files
authored
Use PyEval_InitThreads() as intended (#4350)
* Use `PyEval_InitThreads()` as intended (actually matters only for Python 3.6). * Add `if defined(WITH_THREAD)` condition. https://docs.python.org/3.6/c-api/init.html#c.PyEval_InitThreads > This function is not available when thread support is disabled at compile time. * Fix oversight pointed out by @EricCousineau-TRI: Remove condition that is always false.
1 parent 296615a commit 4894922

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

include/pybind11/detail/internals.h

-3
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,6 @@ PYBIND11_NOINLINE internals &get_internals() {
468468
internals_ptr = new internals();
469469
#if defined(WITH_THREAD)
470470

471-
# if PY_VERSION_HEX < 0x03090000
472-
PyEval_InitThreads();
473-
# endif
474471
PyThreadState *tstate = PyThreadState_Get();
475472
if (!PYBIND11_TLS_KEY_CREATE(internals_ptr->tstate)) {
476473
pybind11_fail("get_internals: could not successfully initialize the tstate TSS key!");

include/pybind11/embed.h

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ inline void initialize_interpreter(bool init_signal_handlers = true,
118118
#if PY_VERSION_HEX < 0x030B0000
119119

120120
Py_InitializeEx(init_signal_handlers ? 1 : 0);
121+
# if defined(WITH_THREAD) && PY_VERSION_HEX < 0x03070000
122+
PyEval_InitThreads();
123+
# endif
121124

122125
// Before it was special-cased in python 3.8, passing an empty or null argv
123126
// caused a segfault, so we have to reimplement the special case ourselves.

0 commit comments

Comments
 (0)