GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-149101: Implement PEP 788 by ZeroIntensity · Pull Request #149116 · python/cpython

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Apr 28, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Hugo has graciously given me permission to backport this if we don't make the May 5th deadline, but let's try to get this done in time!

I will write a full tutorial and migration guide once this is merged; I want to first make sure that this lands before the beta freeze.

  • Issue: Implement PEP 788 -- Protecting the C API from Interpreter Finalization #149101

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bschoenmaeckers and sergey-miryanov reacted with rocket emoji encukou reacted with eyes emoji
All reactions
  • 🚀 2 reactions
  • 👀 1 reaction
ZeroIntensity added 6 commits April 28, 2026 15:49
@ZeroIntensity
Copy the reference implementation.
43b0798
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-788
722dbdf
@ZeroIntensity
Document the new APIs.
73cccbb
@ZeroIntensity
Add a whatsnew entry.
25e1cf0
@ZeroIntensity
Fix stable ABI things.
af1022a
@ZeroIntensity
Fix test_embed.
2fb8419
@ZeroIntensity
ZeroIntensity requested review from a team, AA-Turner, FFY00, encukou and ericsnowcurrently as code owners April 28, 2026 21:41
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 28, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 28, 2026
Implement PEP 788 -- Protecting the C API from Interpreter Finalization #149101
Closed
ZeroIntensity added 2 commits April 28, 2026 17:43
@ZeroIntensity
SIlly news entry.
1096a32
@ZeroIntensity
Documentation fixes.
407062f
@read-the-docs-community

read-the-docs-community Bot commented Apr 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32572982 | 📁 Comparing 53fa94b against main (40dc61a)

  🔍 Preview build  

76 files changed · + 1 added · ± 75 modified

+ Added

  • c-api/slots.html

± Modified

  • glossary.html
  • c-api/concrete.html
  • c-api/exceptions.html
  • c-api/extension-modules.html
  • c-api/index.html
  • c-api/interp-lifecycle.html
  • c-api/lifecycle.html
  • c-api/module.html
  • c-api/perfmaps.html
  • c-api/stable.html
  • and 65 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity and others added 3 commits April 28, 2026 18:09
@ZeroIntensity
Make the sentinel const instead of changing the C analyzer.
a33bdfc
@ZeroIntensity
Fix the html IDs job.
c504a9f
@encukou
Merge branch 'main' into pep-788
f95bfc7
encukou
encukou reviewed Apr 29, 2026
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for adding these!

I'll send notes for Doc/ now; code review coming up.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/c-api/interp-lifecycle.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/interp-lifecycle.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/interp-lifecycle.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/interp-lifecycle.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/interp-lifecycle.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/threads.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/threads.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/threads.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/threads.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/whatsnew/3.15.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity and others added 5 commits April 29, 2026 08:24
@ZeroIntensity @encukou
Apply suggestions from code review
a00bfbb
Co-authored-by: Petr Viktorin <[email protected]>
@ZeroIntensity @encukou
Update Doc/c-api/threads.rst
6ca2499
Co-authored-by: Petr Viktorin <[email protected]>
@ZeroIntensity
Fix lint and remove dead comment.
74259f8
@ZeroIntensity @encukou
Improve new PyThreadState API docs.
eff9b40
Co-authored-by: Petr Viktorin <[email protected]>
@ZeroIntensity
Fix lint.
bc78c10
@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2026
@bedevere-bot

bedevere-bot commented Apr 29, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit bc78c10 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149116%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2026
@encukou

encukou commented Apr 30, 2026

Copy link
Copy Markdown
Member

for buildbots: The RHEL8 failures aren't relevant. Refleaks are worrying though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Apr 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Refleaks are worrying though.

Never mind; main currently leaks (#149179).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity added 14 commits May 5, 2026 16:50
@ZeroIntensity
Fix failure note + use affirmative tone in PyInterpreterView_FromMain…
541169d
… docs.
@ZeroIntensity
Remove usage of _Py_yield.
d75e6d9
@ZeroIntensity
Fix issue with re-entrant clearing.
9f7b014
@ZeroIntensity
Remove needless calls to _PyThreadState_Attach/_PyThreadState_Detach.
f9cb8f7
@ZeroIntensity
Simplify locking in make_pre_finalization_calls.
29fa419
@ZeroIntensity
Fix a few other bugs.
211edf1
@ZeroIntensity
Move some tests to _testinternalcapi.
aaa516e
@ZeroIntensity
Add a test stressing detachment behavior.
e1da86c
@ZeroIntensity
Fix unused test.
95cdd3a
@ZeroIntensity
Release the GIL while joining the thread in test_thread_state_release…
e203fd5
…_with_destructor.
@ZeroIntensity
Fix detached gilstates being attached upon release.
3987445
@ZeroIntensity
Don't use an actual thread for test_thread_state_release_with_destruc…
45d6ece
…tor.

This also allows us to move it to _testcapi.
@ZeroIntensity
Remove dead comment.
319b700
@ZeroIntensity
Fix the C analyzer yet again.
a34dbc6
@ZeroIntensity ZeroIntensity added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 6, 2026
@bedevere-bot

bedevere-bot commented May 6, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit a34dbc6 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149116%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 6, 2026
@colesbury

colesbury commented May 6, 2026

Copy link
Copy Markdown
Contributor

This looks good to me. The only remaining issues I see are minor. GitHub is kind of broken so here are my comments:

  • Some things found by Claude: https://gist.github.com/colesbury/e3ecafad30bb291d205c7be88c7fe7d4 (same as I messaged Peter in Discord)
  • In make_pre_finalization_calls, the atomic compare exchange on finalization_guards should happen before HEAD_UNLOCK(interp->runtime). In other words, we should do both the checks and state transition under the same locks.
  • We don't need both NO_TSTATE_SENTINEL and DETACHED_TSTATE_SENTINEL. You can just keep one or the other.

The comment about tstate->ensure.owned_guard = NULL (" This is usually done by PyThreadState_Clear()...") is confusing to me. The owned_guard = NULL in PyThreadState_Clear is both useless and not a concern of PyThreadState_Clear. These fields are managed by Ensure/Release, not PyThreadState_New/Clear/Delete and we are not clearing or touching any of the other ensure fields. I'd remove that line from PyThreadState_Clear and write the relevant part of PyThreadState_Release as:

    if (tstate->ensure.delete_on_release) {
        ++tstate->ensure.counter;
        PyThreadState_Clear(tstate);
        --tstate->ensure.counter;
    }
    else if (owned_guard != NULL) {
        tstate->ensure.owned_guard = NULL;
    }
ZeroIntensity reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity added 7 commits May 6, 2026 16:44
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-788
9e48209
@ZeroIntensity
Fix whatsnew reference.
59e2d9a
@ZeroIntensity
Fix typos.
7a6cc0c
@ZeroIntensity
Fix test name.
0945129
@ZeroIntensity
Avoid using a second sentinel.
c5148d1
@ZeroIntensity
Do the compare-exchange under the head lock.
adb985f
@ZeroIntensity
Don't try to clear owned_guard in PyThreadState_Clear().
53fa94b
@ZeroIntensity
ZeroIntensity merged commit 2b7c28a into python:main May 6, 2026
82 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity
ZeroIntensity deleted the pep-788 branch May 6, 2026 21:39
@bedevere-app bedevere-app Bot removed the awaiting core review label May 6, 2026
@ZeroIntensity

ZeroIntensity commented May 6, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews, both of you! Sorry again about the rushing.

hugovk reacted with hooray emoji hugovk reacted with rocket emoji
All reactions
  • 🎉 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@befeleme befeleme mentioned this pull request Jun 9, 2026
test_thread_state_ensure is flaky on Fedora Linux s390x #151177
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments
@colesbury colesbury colesbury left review comments
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ZeroIntensity @bedevere-bot @encukou @colesbury
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.