Please document the callback GIL semantics #3532
Unanswered
seerdecker
asked this question in
Q&A
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The doc, the functional.h file, and the examples do not specify the behavior of callbacks with respect to the GIL.
I have a C++ class that calls a std::function callback bound to a Python function from an arbitrary C++ thread asynchronously (e.g. from a C++ thread pool). The main Python thread can be anywhere during that time, e.g. it may be sleeping, it may be calling the C++ class methods with or without py::call_guardpy::gil_scoped_release(), etc.
What happens under the hood during the callback call with respect to the GIL? How must I write the code to ensure that it's safe to call the callback? Right now I'm assuming that Pybind11 will somehow figure out whether it needs to re-acquire the GIL by magic.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions