Skip to content

Grab the GIL on shutdown when checking for exceptions #1832

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

Closed

Conversation

BadSingleton
Copy link
Contributor

@BadSingleton BadSingleton commented Jun 23, 2022

What does this implement/fix? Explain your changes.

The GIL isn't taken when being called from the DomainUnload handler. Take it to avoid a crash when calling Exceptions.ErrorOccurred()

Does this close any currently open issues?

#1831

Checklist

Check all those that are applicable and complete.

The GIL isn't taken when being called from the DomainUnload handler.
@filmor filmor requested a review from lostmsu June 23, 2022 19:41
Comment on lines +361 to +366
var pyGILState = PyGILState.PyGILState_UNLOCKED;
if (!Runtime.HostedInPython)
{
pyGILState = Runtime.PyGILState_Ensure();
}

Copy link
Member

@lostmsu lostmsu Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Py.GIL() no longer tries to force runtime initialization, I think the code would be easier to read with a simple using (Py.GIL()) { ... } around the if.

I don't think it is necessary to check if we are hosted in Python. Runtime.Shutdown further down does not.

Copy link
Member

@lostmsu lostmsu Jun 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another issue is that the code below throws when Python error is set. And that throw prevents the GIL release code to be reached making the GIL unreleasable. Would not be a problem with using Py.GIL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll adjust it accordingly s.t. we can tag rc1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants