-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Avoid GIL deadlocks by calling PyGILState_GetThisThreadState
when using gil_scoped_acquire.
#1211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PyGILState_GetThisThreadState
when using gil_scoped_acquire.PyGILState_GetThisThreadState
when using gil_scoped_acquire.
2c90603
to
dd863d8
Compare
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). |
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
3c37513
Compare
It's fine to merge for me. However, there seems to be something fishy with the CI bots.. (potentially unrelated). |
3c37513
to
74cbb0d
Compare
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
ecc714a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes a problem I've been struggling with for quite some time
ecc714a
to
8ea1025
Compare
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 |
Probably time to merge this. |
8ea1025
to
f0de45a
Compare
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).
f0de45a
to
d04a9b1
Compare
This solved my problem as well, and I would also love to see it merged in asap. |
I re-ran the CI, and it passed all tests now. Apologies that it took quite a while to merge. |
@wjakob: Could we have a release with this patch included? |
@knedlsepp : huh? It was merged some time ago. |
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_Ensure
doesn'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!