Skip to content

invoking std::function inside std::thread hangs #391

Answered by wjakob
samuelpmish asked this question in Q&A
Discussion options

You must be logged in to vote

That's a GIL-related deadlock. bar holds the GIL, and then your thread is trying to re-enter it when calling the Python function func. If those two thread were completely decoupled, then they would simply wait for each other. But you call join() within bar. This should work if you drop the GIL within bar by adding nb::gil_scoped_release guard. However, note that you're not allowed to call other nanobind functions within that scope since they assume that the GIL is held.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@samuelpmish
Comment options

Answer selected by wjakob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants