Skip to content

gh-127791: Fix, document, and test PyUnstable_AtExit #127793

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 7 commits into from
Dec 11, 2024

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Dec 10, 2024

I did several things here:

  • Move the tests to _testcapi instead of _testinternalcapi.
  • Added tests for multiple callbacks (only one was being used, so the issue was avoided).
  • Tests now ensure that the callback is called from the same interpreter.
  • PyUnstable_AtExit now ensures that the caller holds the GIL.
  • Document PyUnstable_AtExit (and link to it in Py_AtExit).
  • Drop the last_ll_callback field on the atexit state (nothing used it).

📚 Documentation preview 📚: https://cpython-previews--127793.org.readthedocs.build/en/127793/c-api/init.html#c.PyUnstable_AtExit

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +30 to +31
PyThreadState *tstate = _PyThreadState_GET();
_Py_EnsureTstateNotNULL(tstate);
Copy link
Member

Choose a reason for hiding this comment

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

You can use PyInterpreterState_Get(), or PyThreadState_Get(), instead: it does the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's better to be explicit rather than do it with one of those.

@vstinner vstinner merged commit d5d84c3 into python:main Dec 11, 2024
50 checks passed
@miss-islington-app
Copy link

Thanks @ZeroIntensity for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @ZeroIntensity and @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker d5d84c3f13fe7fe591b375c41979d362bc11957a 3.13

@vstinner
Copy link
Member

I merged your PR, thanks.

Sadly, the automated backport failed. Would you mind to backport the change manually to 3.13?

ZeroIntensity added a commit to ZeroIntensity/cpython that referenced this pull request Dec 11, 2024
@bedevere-app
Copy link

bedevere-app bot commented Dec 11, 2024

GH-127819 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Dec 11, 2024
@ZeroIntensity ZeroIntensity deleted the fix-pyunstable-atexit branch December 11, 2024 11:31
vstinner pushed a commit that referenced this pull request Dec 11, 2024
) (#127819)

* Fix merge conflicts.

* [3.13] gh-127791: Fix, document, and test `PyUnstable_AtExit` (GH-127793)
(cherry picked from commit d5d84c3)

Co-authored-by: Peter Bierma <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
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.

2 participants