Replies: 2 comments 2 replies
-
Python threads are real threads, but they are often hobbled by the GIL. Pybind, however, allows you to release the GIL in long-running C++ code that doesn't need to touch Python, which will leave that thread running the C++ code while it switches to another thread for Python execution. Have a look at https://pybind11.readthedocs.io/en/stable/advanced/misc.html#global-interpreter-lock-gil for how to interact with the GIL for allowing this. |
Beta Was this translation helpful? Give feedback.
-
Calling python callback from C++ acquire GIL automatically py::gil_scope_acquire gil{};
// We now have the GIL, so it's safe to use py:: objects and call into Python code
g(intermediate_value);
|
Beta Was this translation helpful? Give feedback.
-
Hi,
There is a class in C++ shared library, and the class' functions are called by Python using
Pybind
.How to call the functions using multithreading? I tried multiple threading in Python, but it is not real multiple threading (due to GIL)
The use case is Python handles HTTP requests and then calls C++ functions. As there are concurrent requests, using multiple threading to call C++ functions is desired.
Thanks for your help.
Beta Was this translation helpful? Give feedback.
All reactions