Remove PyEval_ThreadsInitialized() assertion #110

First, this function should not be called before `Py_Initialize()`.
It accesses the field `_PyRuntime.ceval.gil.locked` of the global
variable, which is zero initially, but uses -1 to indicate that
the GIL is not created or destroyed.
(8ff5356473/Python/ceval_gil.h (L98))

Second, this assertion can't be moved after `Py_InitializeEx(0)` call,
because in Python 3.7 they started calling `PyEval_InitThreads()`
from `Py_Initialize()`.
(2914bb32e2 (diff-baf5eab51059d96fb8837152dab0d1a4R689))
This commit is contained in:
Vlad Shcherbina 2018-02-10 21:36:59 +03:00
parent 8b7a57891b
commit 81fd4bd24e
1 changed files with 0 additions and 2 deletions

View File

@ -41,8 +41,6 @@ pub fn prepare_freethreaded_python() {
// as we can't make the existing Python main thread acquire the GIL. // as we can't make the existing Python main thread acquire the GIL.
assert_ne!(ffi::PyEval_ThreadsInitialized(), 0); assert_ne!(ffi::PyEval_ThreadsInitialized(), 0);
} else { } else {
// If Python isn't initialized yet, we expect that Python threading isn't initialized either.
assert_eq!(ffi::PyEval_ThreadsInitialized(), 0);
// Initialize Python. // Initialize Python.
// We use Py_InitializeEx() with initsigs=0 to disable Python signal handling. // We use Py_InitializeEx() with initsigs=0 to disable Python signal handling.
// Signal handling depends on the notion of a 'main thread', which doesn't exist in this case. // Signal handling depends on the notion of a 'main thread', which doesn't exist in this case.