Uh oh!
There was an error while loading. Please reload this page.
Avoid GIL deadlocks by calling PyGILState_GetThisThreadState when using gil_scoped_acquire. - #1211
Conversation
PyGILState_GetThisThreadState when using gil_scoped_acquire.PyGILState_GetThisThreadState when using gil_scoped_acquire.2c90603 to
dd863d8Comparebzarco
commented
Jan 6, 2018
Some more details about this issue: Currently in The problem is that if we try to acquire the GIL in one of these threads (where state was created in The solution proposed in this pull request checks if a thread state was created using the |
This looks good to me. I've verified that it doesn't break the "advanced" use case in pybind11 (migrating Python to a different thread). |
jagerman
commented
Jan 11, 2018
Looks good to me. Should we tag this for 2.2.2? It's a "feature" of sorts, but the actual code change here is just one Python functional call. |
dd863d8 to
3c37513Comparebzarco
commented
Mar 4, 2018
wjakob
commented
Mar 5, 2018
It's fine to merge for me. However, there seems to be something fishy with the CI bots.. (potentially unrelated). |
3c37513 to
74cbb0dComparebzarco
commented
Mar 5, 2018
Seems like an environment issue? Only one OS X run is failing: Xcode: xcode9 C++ PYTHON=3.6 CPP=14 CLANG DEBUG=1 |
682b2ba to
ecc714aCompare
heyer2
left a comment
There was a problem hiding this comment.
Fixes a problem I've been struggling with for quite some time
ecc714a to
8ea1025Compareoremanj
commented
May 1, 2018
I'll put in a vote for this change as well - I ran into the problem it's fixing, and I don't see how |
heyer2
commented
Aug 3, 2018
Probably time to merge this. |
8ea1025 to
f0de45aCompareThis avoids GIL deadlocking when pybind11 tries to acquire the GIL in a thread that already acquired it using standard Python API (e.g. when running from a Python thread).
f0de45a to
d04a9b1Comparedavidbaraff
commented
Nov 30, 2018
This solved my problem as well, and I would also love to see it merged in asap. |
wjakob
commented
Dec 1, 2018
I re-ran the CI, and it passed all tests now. Apologies that it took quite a while to merge. |
knedlsepp
commented
Jul 29, 2019
@wjakob: Could we have a release with this patch included? |
wjakob
commented
Jul 29, 2019
@knedlsepp : huh? It was merged some time ago. |
knedlsepp
commented
Jul 29, 2019
I'm sorry about the noise. I did only check: e2b884c and github usually lists the tags/branches that contain a particular commit below the commit message. It didn't show that for me when I checked. I did again check the link and now it is listed as part of master and 2.3.0. Don't know why I couldn't observe it before. Thanks for getting back to me! |
This avoids GIL deadlocking when pybind11 tries to acquire the GIL in a thread that already acquired it using standard Python API (e.g. when running from a Python thread).
Simple code reproducing the problem:
I know this can be solved by releasing the GIL during C++ execution, but I don't think it should be something that is required (which currently is in a multi-threaded Python application). Moreover,
PyGILState_Ensuredoesn't deadlock when running the same code.Please let me know if I am missing anything. And thank you for creating and maintaining such a great project!