Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-119241: Add HOWTO for free-threaded C API extensions#119877

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

colesbury
Copy link
Contributor

@colesburycolesbury commentedMay 31, 2024
edited
Loading

Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
@colesbury
Copy link
ContributorAuthor

There is more I'd like to add to the HOWTO, such as information on critical sections or other synchronization primitives if/when those APIs become public, but I think that even in the current form will be useful.

cc@ngoldbaum

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@ncoghlan
Copy link
Contributor

ncoghlan commentedMay 31, 2024
edited
Loading

Question that came to mind when reading was whether there is a way to compile a single binary extension that is usable on both free threaded and GIL protected builds (if the latter are still looking for an official name, I offer that as a suggestion).

Also (if that is possible) how to check at runtime whether the GIL is enabled or not.

The content that is there looks good, though!

@ncoghlan
Copy link
Contributor

Direct link to the preview:https://cpython-previews--119877.org.readthedocs.build/en/119877/howto/free-threading-extensions.html

colesbury reacted with thumbs up emoji

@colesbury
Copy link
ContributorAuthor

...whether there is a way to compile a single binary extension that is usable on both free threaded and GIL protected builds

No, that's not currently possible. That's something we hope to address in 3.14 with support for the limited API and stable ABI.

ncoghlan reacted with thumbs up emoji

@da-woods
Copy link
Contributor

I don't know if this is the right place to document it but it might be:

If you use the Windows installer then you end up with one copy of pyconfig.h that doesn't havePy_GIL_DISABLED set. What that means is that running something likepython313t setup.py build_ext --inplace will generate an extension that's named as if it's a free-threading extension (e.g.something.cp313t-win_amd64.pyd) but actually isn't. This will crash on import.

The upshot is that people building extensions on Windows will most likely have to manually definePy_GIL_DISABLED themselves.

colesbury reacted with thumbs up emoji

Most of the C API is thread-safe, but there are some exceptions.

* **Struct Fields**: Accessing struct fields directly is not thread-safe if
the field may be concurrently modified.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe clarify that you're talking about C structs provided by the CPython C API.

colesbury reacted with thumbs up emoji
`setuptools <https://setuptools.pypa.io/en/latest/setuptools.html>`_ to build
your extension and currently set ``py_limited_api=True`` you can use
``py_limited_api=not sysconfig.get_config_var("Py_GIL_DISABLED")`` to opt out
of the limited API when building with the free-threaded build.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe worth adding a note that this implies that they'll need to set up wheel builds specifically for the free-threaded build if they want to ship free-threaded binaries and otherwise rely on the limited API to only produce a single wheel per platform.

colesbury reacted with thumbs up emoji
@colesbury
Copy link
ContributorAuthor

I've updated the docs with the above feedback and moved some things into a "Building Extensions for the Free-Threaded Build" section.

@da-woods
Copy link
Contributor

Looks good to me (but I doubt it's my review that you're waiting on)

@colesburycolesbury merged commit02b272b intopython:mainJun 18, 2024
27 checks passed
@miss-islington-app
Copy link

Thanks@colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@colesburycolesbury deleted the gh-119241-capi-free-threaded-howto branchJune 18, 2024 13:49
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJun 18, 2024
…GH-119877)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.(cherry picked from commit02b272b)Co-authored-by: Sam Gross <colesbury@gmail.com>Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
@bedevere-app
Copy link

GH-120693 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJun 18, 2024
colesbury added a commit that referenced this pull requestJun 18, 2024
…9877) (#120693)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.(cherry picked from commit02b272b)Co-authored-by: Sam Gross <colesbury@gmail.com>Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
@encukou
Copy link
Member

Note that the HOWTO index was just reorganized (GH-119366); this HOWTO is currently missing from the rendered table of contents. Fix is inGH-120703.

picnixz pushed a commit to picnixz/cpython that referenced this pull requestJun 19, 2024
…#119877)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
encukou pushed a commit that referenced this pull requestJun 20, 2024
…3 logical sections (GH-119366,GH-120703) (GH-120646)Update the documentation howto index page and group docs into 3 logical sections (GH-119366)(cherry picked from commita26d27e)Includes a follow-up fix to properly mergeGH-119877:* Add a link to free-threading HOWTO to the index (GH-120703)  (cherry picked from commit45d5cab)Co-authored-by: Carol Willing <carolcode@willingconsulting.com>Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
mrahtz pushed a commit to mrahtz/cpython that referenced this pull requestJun 30, 2024
…#119877)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull requestJul 11, 2024
…#119877)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
estyxx pushed a commit to estyxx/cpython that referenced this pull requestJul 17, 2024
…#119877)Some sections adapted fromhttps://github.com/Quansight-Labs/free-threaded-compatibility/written by Nathan Goldbaum.Co-authored-by: Nathan Goldbaum <nathan.goldbaum@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@itamaroitamaroitamaro left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra left review comments

@ngoldbaumngoldbaumngoldbaum left review comments

@ncoghlanncoghlanncoghlan approved these changes

Assignees
No one assigned
Labels
docsDocumentation in the Doc dirskip newstopic-free-threading
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@colesbury@ncoghlan@da-woods@encukou@itamaro@JelleZijlstra@ngoldbaum

[8]ページ先頭

©2009-2025 Movatter.jp