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-146636: Add Free-threaded Stable ABI migration guide by clin1234 · Pull Request #148453 · python/cpython

Conversation

@clin1234

@clin1234 clin1234 commented Apr 12, 2026 •
edited by github-actions Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor
  • Issue: Implement PEP 803 -- abi3t #146636

📚 Documentation preview 📚: https://cpython-previews--148453.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Apr 12, 2026
@github-project-automation github-project-automation Bot added this to Docs PRs Apr 12, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Apr 12, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 12, 2026
Implement PEP 803 -- abi3t #146636
Closed
8 of 9 tasks
da-woods
da-woods reviewed Apr 12, 2026
View reviewed changes

@da-woods da-woods left a comment

Copy link
Copy Markdown
Contributor

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.

There's a lot that isn't right here (or is mostly about freethreading generally rather than about the stable ABI).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

Comment thread Doc/howto/freethreading-stable-abi.rst Outdated
:c:func:`PyDict_SetItem`, or explicitly using macros), it attempts to acquire
the underlying mutex.

Using Critical Sections

@da-woods da-woods Apr 12, 2026

Copy link
Copy Markdown
Contributor

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.

The weakness right now is that I don't think they're part of the stable ABI (but hopefully will be)

Sorry, something went wrong.

Uh oh!

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

All reactions

@clin1234 clin1234 Apr 12, 2026

Copy link
Copy Markdown
Contributor Author

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.

If you were referring to https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItem, it's part of the Stable ABI: https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItem

Sorry, something went wrong.

Uh oh!

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

All reactions

@da-woods da-woods Apr 12, 2026

Copy link
Copy Markdown
Contributor

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.

No - I was referring to critical sections. Which I really hope are added before 3.15 comes out but I don't think currently are. Sorry if that was ambiguous.

Sorry, something went wrong.

Uh oh!

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

All reactions

@clin1234 clin1234 May 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

Now being proposed: #149225

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

@da-woods

da-woods commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

I think the way most people will want to proceed is:

  1. Switch to PEP 793 module initialization (https://peps.python.org/pep-0793/). This will hopefully be a fairly trivial change for most people.
  2. Switch to using opaque objects and accessing all their type data through PyObject_GetTypeData. This will be a painful change for most people (and especially if they're starting from static types).
  3. Follow the general free-threading C API advice in https://docs.python.org/3/howto/free-threading-extensions.html#container-thread-safety (e.g. avoid borrowed reference, use critical sections once they become available). My personal opinion is that it isn't worth duplicating the advice.
  4. Decide if they want to mark their extension as thread-safe.

But steps 1 and 2 are the main ones and are almost not covered here.

All reactions

Sorry, something went wrong.

Uh oh!

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

da-woods
da-woods reviewed Apr 12, 2026
View reviewed changes
Comment thread Doc/howto/freethreading-stable-abi.rst Resolved

Uh oh!

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

@clin1234

clin1234 commented Apr 12, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Based on WIP PR: #148013

All reactions

Sorry, something went wrong.

Uh oh!

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

@picnixz

picnixz commented Apr 12, 2026

Copy link
Copy Markdown
Member

I don't understand why we are having this PR when the reference documentation is not merged. Can we revisit this later? I would have expected the PEP's author to write this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@picnixz
picnixz marked this pull request as draft April 12, 2026 17:03
@bedevere-app bedevere-app Bot removed the awaiting review label Apr 12, 2026
@clin1234
clin1234 marked this pull request as ready for review April 12, 2026 17:44
@bedevere-app bedevere-app Bot added the awaiting review label Apr 12, 2026
@picnixz picnixz added the DO-NOT-MERGE label Apr 13, 2026
@picnixz

picnixz commented Apr 13, 2026

Copy link
Copy Markdown
Member

I left it as a draft because I do not think it is time for it to be reviewed. Please wait for the PEP author first.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented Apr 13, 2026

Copy link
Copy Markdown
Member

Please don't repeat text from free-threading HOWTO. This document should be about migrating from that to the stable ABI; anything that's relevant to free-threading in general should be explained there (and possibly linked from the new document).

Also don't repeat information from the reference docs. A migration guide should link to the docs, and perhaps point out how/why the new thing is different.

And please see here on how-to guides in general: https://diataxis.fr/how-to-guides/

All reactions

Sorry, something went wrong.

Uh oh!

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

@read-the-docs-community

read-the-docs-community Bot commented May 2, 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 #32725685 | 📁 Comparing 3b401db against main (be9c7cb)

  🔍 Preview build  

101 files changed · + 3 added · ± 98 modified

+ Added

  • c-api/slots.html
  • howto/freethreading-stable-abi.html
  • whatsnew/3.16.html

± Modified

  • glossary.html
  • index.html
  • c-api/concrete.html
  • c-api/dict.html
  • c-api/exceptions.html
  • c-api/extension-modules.html
  • c-api/gcsupport.html
  • c-api/index.html
  • c-api/interp-lifecycle.html
  • c-api/lifecycle.html
  • and 88 more...
All reactions

Sorry, something went wrong.

Uh oh!

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

@clin1234
clin1234 requested a review from da-woods May 7, 2026 19:31
@clin1234
clin1234 marked this pull request as draft May 7, 2026 19:31
@bedevere-app bedevere-app Bot removed the awaiting review label May 7, 2026
@clin1234
clin1234 force-pushed the patch-6 branch from a4b1bea to 0bddc53 Compare May 13, 2026 23:50
@clin1234
clin1234 marked this pull request as ready for review May 17, 2026 09:33
@bedevere-app bedevere-app Bot added the awaiting review label May 17, 2026
clin1234 added 5 commits May 17, 2026 05:33
@clin1234
Add reference to freethreading-stable-abi-howto
8040796
@clin1234
Add documentation for Free Threading Stable ABI usage
7175e14
This document provides detailed instructions on how to use the Free Threading Stable ABI in CPython, including guidelines for module initialization, API usage, and thread safety considerations.
@clin1234
Update documentation on PyObject opaqueness and module init
e0f3bd2
Clarified access restrictions on PyObject members and recommended functions for type and reference count manipulation.
@clin1234
Fix formatting for PyObject opaqueness section
3739aec
@clin1234
Fix formatting of code snippet in documentation
c235a75
clin1234 and others added 9 commits May 17, 2026 05:33
@clin1234
Update documentation on PyObject opaqueness
753156b
Clarified that direct access to PyObject members is prohibited.
@clin1234 @da-woods
Py_Type
344105e
Co-authored-by: da-woods <[email protected]>
@clin1234
Clarify free-threaded limited API build documentation
29b932d
Updated documentation to clarify the identification of free-threaded limited API builds in C, including changes to macros and initialization methods.
@clin1234
Revise freethreading-stable-abi.rst for clarity
8545eeb
Updated the documentation to clarify the use of the stable ABI and GIL management in Python extensions, including changes to member access and initialization methods.
@clin1234
Add freethreading-stable-abi.rst to documentation index
2a11368
@clin1234
Simplify threading and API guidelines in documentation
2f2e756
Removed sections on API guidelines, critical sections, and thread safety from the documentation.
@clin1234
Update freethreading-stable-abi.rst
5d23810
@clin1234
Update freethreading-stable-abi.rst
a8294fa
@clin1234
Update freethreading-stable-abi.rst
43538cf
@clin1234
clin1234 force-pushed the patch-6 branch from 0bddc53 to 43538cf Compare May 17, 2026 09:33
@clin1234
Update module slot definitions to use PySlot from PEP 820
ed0e4fe
da-woods
da-woods reviewed May 17, 2026
View reviewed changes
Comment thread Doc/howto/freethreading-stable-abi.rst Outdated
Comment on lines +17 to +18
The CPython C API exposes the :c:macro:`!Py_LIMITED_API` macro: in the free-threaded stable ABI
build it's defined to ``1``, and in the regular build it's not defined.

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

This isn't right.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst Outdated
Comment on lines +28 to +32
- define both :c:macro:`!Py_LIMITED_API` and :c:macro:`!Py_TARGET_ABI3T`, or
- define only :c:macro:`!Py_LIMITED_API` and:

- on Windows, define :c:macro:`!Py_GIL_DISABLED`;
- on other systems, use the headers of free-threaded build of Python.

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

I think the idiomatic way is probably just to define Py_TARGET_ABI3T with the version hex that you want to target.

The other ways (involving defining Py_LIMITED_API and maybe using the free-threading headers) are a bit opaque so it's probably better not to recommend them.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst Outdated
Comment on lines +37 to +38
Accessing any member of ``PyObject`` directly is now prohibited, like the non-GIL
stable ABI. For instance, prefer ``Py_TYPE()`` and ``Py_SET_TYPE()`` over ``ob_type``,

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

like the non-GIL stable ABI

I think this is the wrong way around and it's "the GIL stable ABI".

I think also that accessing the members is recommended against in the GIL stable ABI and actually impossible in the freethreading stable ABI.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst
the GIL disabled; otherwise importing the extension will raise a warning and
enable the GIL at runtime.

Multi-phase and single-phase initialization is supported to indicate that an extension module

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

I don't think single-phase initialization is supported

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst
PySlot_END
};

Furthermore, using ``PyABIInfo_VAR`` and ``Py_mod_abi`` is recommended so that an

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

required I think

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst Outdated

.. _critical-sections:

Replacements:

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

At least in the C and C++ world the macros are available and encouraged. So I'm not sure "replacements" makes sense.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst
Comment on lines +119 to +124
|:c:macro:`Py_BEGIN_CRITICAL_SECTION_MUTEX` |``PyCriticalSection_BeginMutex`` |
|:c:macro:`Py_END_CRITICAL_SECTION` |``PyCriticalSection_End`` |
+-------------------------------------------+---------------------------------------+
|:c:macro:`Py_BEGIN_CRITICAL_SECTION2_MUTEX`|``PyCriticalSection2_BeginMutex`` |
|:c:macro:`Py_END_CRITICAL_SECTION2` |``PyCriticalSection2_End`` |
+-------------------------------------------+---------------------------------------+

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

I don't think the mutex versions are exposed at all

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Doc/howto/freethreading-stable-abi.rst
``Py_REFCNT``, ``Py_IncRef()`` and ``Py_DecRef()`` over ``ob_refcnt``, etc.

Similarly, members of ``PyVarObject`` are not visible. If you need any object of such type
to be passed as a ``PyObject`` parameter to any API function, cast it directly as ``PyObject``.

@da-woods da-woods May 17, 2026

Copy link
Copy Markdown
Contributor

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.

The big consequence here is not that you can't access the members. It's that you can't define structures like

struct S {
    PyObject_HEAD
    // your struct goes here
};

and thus have to omit the PyObject_HEAD and set the object size to -size to indicate opaqueness.

You also can't use PyVarObject at all easily right now.

Sorry, something went wrong.

Uh oh!

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

All reactions
clin1234 added 3 commits May 17, 2026 11:22
@clin1234
Update freethreading-stable-abi.rst
a7fcbcc
@clin1234
Fix typo in freethreading-stable-abi.rst
ccdedb0
@clin1234
Update freethreading-stable-abi.rst
3b401db
@encukou

encukou commented May 28, 2026

Copy link
Copy Markdown
Member

Thank you @clin1234. I'll take it from here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@clin1234

clin1234 commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @clin1234. I'll take it from here.

Any other major PRs as part of implementing PEP 803 that should be mentioned in the Migration Guide?

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou

encukou commented May 29, 2026

Copy link
Copy Markdown
Member

Continued in #150580.

Any other major PRs as part of implementing PEP 803 that should be mentioned in the Migration Guide?

Mentions should go in Release notes; a guide should rather be full of practical advice.
All the PRs should be attached to #146636 though.

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou encukou closed this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@da-woods da-woods da-woods left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review DO-NOT-MERGE docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Todo

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

@clin1234 @da-woods @picnixz @encukou
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.