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
In my code, I start an asynchronous thread in C++ to execute wait_step by calling a wait function in Python. This thread waits for the result from another C++ thread and writes the result back to the asyncio.future object after obtaining it. Since the call in Python is asynchronous, many C++ threads might be executing wait_step at the same time.
However, I encountered an issue where the wait_step function in C++ occasionally deadlocks when acquiring the GIL with py::gil_scoped_acquire acquire{}. I tried using a count to record the number of threads entering this code simultaneously. Theoretically, the printed count value should always be 1, but I got results greater than 1. Does this mean that multiple C++ threads are acquiring the GIL simultaneously?
Then, I tried adding std::mutex before entering the code segment, and the deadlock did not occur again.
I have looked into some other related issues, but they did not solve my problem. #1087
why does this happen? Am I using py::gil_scoped_acquire incorrectly, or are there implicit rules I haven’t followed (such as proper initialization of the interpreter, GIL, etc.)?
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
-
and the python code like:
In my code, I start an asynchronous thread in C++ to execute
wait_step
by calling await
function in Python. This thread waits for the result from another C++ thread and writes the result back to the asyncio.future object after obtaining it. Since the call in Python is asynchronous, many C++ threads might be executing wait_step at the same time.However, I encountered an issue where the wait_step function in C++ occasionally deadlocks when acquiring the GIL with
py::gil_scoped_acquire acquire{}
. I tried using a count to record the number of threads entering this code simultaneously. Theoretically, the printed count value should always be 1, but I got results greater than 1. Does this mean that multiple C++ threads are acquiring the GIL simultaneously?Then, I tried adding std::mutex before entering the code segment, and the deadlock did not occur again.
I have looked into some other related issues, but they did not solve my problem.
#1087
why does this happen? Am I using py::gil_scoped_acquire incorrectly, or are there implicit rules I haven’t followed (such as proper initialization of the interpreter, GIL, etc.)?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions