Linux: Fix a rare crash that could occur when shutting down an interpreter running multiple threads #324
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
when some of those threads are in greenlets making calls to functions that release the GIL.
When Python notices that the thread would like to obtain the GIL again, but the interpreter is exiting, it calls
pthread_exit
. With GCC/libstdc++ at least, this ultimately "raises" what is meant to be an uncatchable exception in order to cause the stack to unwind and destructors to run. But if anoexcept
function is in the call stack, then attempting to unwind through that function (with this uncatchable exception in place) would trigger the runtime to think that we had violated our dynamic exception specification, and callstd::terminate()
— so even though the program had otherwise exited cleanly, this one background thread was ruining it for everyone.The solution is to be more careful with our
noexcept
functions.Interestingly, the situation with the windows C/C++ runtime is exactly opposite.