You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a mixed C and C++ program that uses pybind11, but I am running into issues with the GIL.
My main.c code calls some threaded program, which is written in C, too. This threaded program waits for an event, and when the event occurs, it calls a C++ program that has embedded Python.
I have tried using py::gil_scoped_acquire acquire and py::gil_scoped_release release around the Python critical sections in the C++ code, but I either get a deadlock or seg fault.
Does anyone know how to use pybind11 with a threaded program?
UPDATE:
I seem to have figured it out. You have to use:
Py_BEGIN_ALLOW_THREADS
... Do some blocking I/O operation ...
Py_END_ALLOW_THREADS
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a mixed C and C++ program that uses pybind11, but I am running into issues with the GIL.
My main.c code calls some threaded program, which is written in C, too. This threaded program waits for an event, and when the event occurs, it calls a C++ program that has embedded Python.
I have tried using py::gil_scoped_acquire acquire and py::gil_scoped_release release around the Python critical sections in the C++ code, but I either get a deadlock or seg fault.
Does anyone know how to use pybind11 with a threaded program?
UPDATE:
I seem to have figured it out. You have to use:
as stated by https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions