From d77fb7155db64a26909d44581596472c1a2225c9 Mon Sep 17 00:00:00 2001 From: Armin Rigo Date: Sat, 19 Oct 2019 10:00:31 +0200 Subject: Issue #427 Fix: it's invalid according the API to call PyGILState_Release(PyGILState_UNLOCKED) manually at startup to release the GIL. Instead we must call another function, like PyEval_SaveThread(). The difference shows up in a rare case on CPython 3.7 only. --- cffi/_embedding.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'cffi') diff --git a/cffi/_embedding.h b/cffi/_embedding.h index d11b62a..764820e 100644 --- a/cffi/_embedding.h +++ b/cffi/_embedding.h @@ -327,13 +327,15 @@ static int _cffi_carefully_make_gil(void) #endif /* call Py_InitializeEx() */ - { - PyGILState_STATE state = PyGILState_UNLOCKED; - if (!Py_IsInitialized()) - _cffi_py_initialize(); - else - state = PyGILState_Ensure(); - + if (!Py_IsInitialized()) { + _cffi_py_initialize(); + PyEval_InitThreads(); + PyEval_SaveThread(); /* release the GIL */ + /* the returned tstate must be the one that has been stored into the + autoTLSkey by _PyGILState_Init() called from Py_Initialize(). */ + } + else { + PyGILState_STATE state = PyGILState_Ensure(); PyEval_InitThreads(); PyGILState_Release(state); } -- cgit v1.2.1