Author Roffild
Recipients Roffild
Date 2019-06-07.00:03:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Everyone uses GIL wrong! = DEADLOCK

I used sub-interpreters in embedded Python:

PyGILState_Ensure() = DEADLOCK

A deadlock happens in the line:

Of course in the help there is the note:
Note that the PyGILState_() functions assume there is only one global interpreter (created automatically by Py_Initialize()). Python supports the creation of additional interpreters (using Py_NewInterpreter()), but mixing multiple interpreters and the PyGILState_() API is unsupported.

But functions PyGILState_() are used in third-party libraries. Most often, these functions are used without checking that GIL is already locked. Often, these functions are added to the code for reinsurance only and this can affect performance.



Pybind11 developers have already fixed this problem:

It is necessary to change the code of PyGILState_() functions to support sub-interpreters.

Or add to warning:
Some Python libraries cannot be used in a sub-interpreter due to the likelihood of deadlock.

For me, this is a critical vulnerability!

There is another problem:
Calling PyEval_AcquireThread() again results in a deadlock. This can be controlled in your code, but not in a third-party library.
Date User Action Args
2019-06-07 00:03:04Roffildsetrecipients: + Roffild
2019-06-07 00:03:04Roffildsetmessageid: <>
2019-06-07 00:03:04Roffildlinkissue37186 messages
2019-06-07 00:03:04Roffildcreate