diff options
author | Armin Rigo <arigo@tunes.org> | 2019-10-19 10:00:31 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2019-10-19 10:00:31 +0200 |
commit | d77fb7155db64a26909d44581596472c1a2225c9 (patch) | |
tree | 462cd397edb463259f8b4fd7f2cb2f5d28f34809 | |
parent | 45d5b2cd9d698c0ed0eb787cf13dafacb3ac64c5 (diff) | |
download | cffi-d77fb7155db64a26909d44581596472c1a2225c9.tar.gz |
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.
-rw-r--r-- | cffi/_embedding.h | 16 |
1 files changed, 9 insertions, 7 deletions
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); } |