-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Calling python function from thread created in C++ #1723
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
Comments
You're crossing over into GIL (Global Interpreter Lock) territory - good luck! If your C++ bindings are relatively small, then you should play around with If your bindings are rather large and comprehensive, I'd suggest trying to think of alternative ways of doing things... Perhaps Python's |
Any tips why with such gil guard:
the script doesn't deadlock nor throws any error, but simply doesn't call the passed function and exits silently? |
Could #1273 help? |
Also, does your repro versino incorporating #1211 in |
Er, I don't know exactly why, but the following (I think?) fixes your code (on my machine for my setup...): Some wild speculation / suggestions:
I added a comment there about maybe making some wrapper code that will auto-GIL acquire for any If you wanna see some wacky but generic argument wrapper code stuff, here you go: |
I fixed that by releasing the gil in a proper place. I added a method:
For some reason doing this in the Executor's destructor didn't work. |
Hi, Wouldn't that have just been because the call to Executor's destructor is non-deterministic (since it is emitted by the Python garbage collector)? Just asking? Cheers & thanks for the examples & solutions. I'm coming from the C++ world & only just beginning to feel my way into the world of Python via pybind11. |
I encountered a problem when trying to implement functionality similar to that on the snippet.
testing it with this python code:
The behavior is nondeterministic. For some runs it goes without any error and sometimes it ends with SEGFAULT. I saw similar issues here but none of the solutions worked for me. I tried to put gil_scoped_acquire and gil_scoped_release in every possible combination but in the result the python function was not called without any error, or just segmentation fault happened.
The text was updated successfully, but these errors were encountered: