Author: Armin Rigo <[email protected]>
Branch:
Changeset: r3299:7d1496495e25
Date: 2019-10-19 10:00 +0200
http://bitbucket.org/cffi/cffi/changeset/7d1496495e25/
Log: 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.
diff --git a/cffi/_embedding.h b/cffi/_embedding.h
--- a/cffi/_embedding.h
+++ b/cffi/_embedding.h
@@ -327,13 +327,15 @@
#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);
}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit