-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Resolve threading issue with gil_scoped_acquire #1556
Conversation
It was possible for python threads to execute c++ code which would subsequently call gil_scoped_acquire, incorrectly conclude that the gil was not held, and then deadlock.
|
||
|
||
def test_no_deadlock(): | ||
# This code would deadlock - see issue 1525 |
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.
I wanted to write a test case, but I am unsure if adding code than can potentially deadlock the test suite is wise. Other solutions warranted, can remove the test case altogether if preferred.
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.
Looks like at least on CI the deadlock is handled cleanly!
Looks like this has only worked for Python 3, not 2 (my dev box is Python 3). I'd like to give this another shot that works for both platforms. Would be great if anyone familar with this part of the codebase can weigh in on whether I'm heading on the right path before I spend too much time on this. |
Hi David, This PR is critical to me too, I found out that running my C-extensions which acquire gil from non-main python thread dead-lock. Do you know when this PR will be accepted? Thanks a lot! |
Hi @awaizman1, at the moment I'm avoiding threads as much as possible and other workarounds, but I'm sure this is going to really bite me soon. I'd love to push forward with further development and get it fixed but I'm waiting to see if we can get any interest from the pybind11 maintainers first... |
@davidhewitt I'm sure that in the first place we should consider helping each other (and giving ideas) to resolve issues and walk around corner cases we face as users of this great library. So can't wait for this PR to be finished. |
It was possible for python threads to execute c++ code which would subsequently call gil_scoped_acquire, incorrectly conclude that the gil was not held, and then deadlock.
The most basic example I can build of the failing code is:
and then invoked in python as so:
I believe that this patch will resolve both #1525 and #1308.
To me this is a critical problem, as I often work with python threads. I would be very grateful if this can be reviewed and merged in time for the pybind11 2.3 release.
I am happy to make any changes you feel necessary, including writing a different solution altogether if you have a better one in mind.
Thanks in advance,
David