-
Notifications
You must be signed in to change notification settings - Fork 133
Release the GIL whenever possible to allow multithreading from python #123
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
@vlarsson Check this PR is you are ok with it. |
My understanding of the python GIL is limited. I don't know if there is any benefit in having some of these as callguards So am I correct in understanding that we need to have the GIL whenever we write to py::dict? Or why are we re-acquiring the GIL in some of these? |
@vlarsson as far as I know, whenever we deal with python objects we should hold the GIL. When writing this PR, I experimented with simply always releasing the GIL, but unsurprisingly I got crashes. Maybe writing an entirely new object (py::dict) can be ok, but I wouldn't risk it.
I will also experiment with not re-acquiring the GIL when writing |
@vlarsson Holding the GIL while writing I changed the code to use |
44f44aa
to
f430abb
Compare
Ah sorry, the recent PR #125 added some merge conflicts to this. Could you fix this? and then we can merge it. |
f430abb
to
645ba68
Compare
Should be ok now |
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.
Thanks!
This enables multithreading from within python. Example experiment:
Output on my machine before:
After: