bpo-39877: Remove useless PyEval_InitThreads() calls by vstinner · Pull Request #18883 · python/cpython
PyEval_InitThreads(); PyEval_ReleaseThread(mainstate);
gilstate = PyGILState_Ensure();
/* 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!");