Ensure GIL is released after exception is thrown #27013
Merged
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.
Ensure that the Python GIL is released when an exception is thrown from an initializer.
The pattern taken by our throwing initializers for the Python module is that the super class Value.init acquires the GIL, and then the super class Value.postinit releases the GIL (after all init's have fired). However, based on recent discussions (see #26997 and #26990) these calls cannot rely on a postinit being called when an exception is thrown.
Prior to this PR, if an exception was thrown in the init, the GIL would never be released. This PR resolves the problem by explicitly handling the exception in the init, releasing the GIL, and then rethrowing the caught exception.
start_test test/library/packages/Python
[Reviewed by @lydia-duncan]