Skip to content

Ensure GIL is released after exception is thrown #27013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025

Conversation

jabraham17
Copy link
Member

@jabraham17 jabraham17 commented Mar 28, 2025

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.

  • Ran start_test test/library/packages/Python

[Reviewed by @lydia-duncan]

Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
Signed-off-by: Jade Abraham <[email protected]>
@jabraham17
Copy link
Member Author

Noting that I am actively working on #27029 with is going to conflict with this PR. I am waiting to merge this until #27029 is merged, at that time I will update this PR to match

@jabraham17 jabraham17 merged commit 3ca8512 into chapel-lang:main Apr 9, 2025
10 checks passed
@jabraham17 jabraham17 deleted the ensure-gil-release branch April 9, 2025 22:21
jabraham17 added a commit that referenced this pull request Apr 9, 2025
Fix a few merge conflicts caused by
#27044 and
#27013

[Not reviewed - trivial]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants