Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BaLinuss
Copy link
Contributor

@BaLinuss BaLinuss commented Dec 1, 2025

Python 3.14 now supports true concurrency. For that you need to set the --disable-gil flag.
For that I added the option gil that is true as default. When set to false, the --disable-gil flag is configured.

@BaLinuss BaLinuss changed the title Added GIL removal as option Added GIL removal as option for python Dec 1, 2025
Copy link
Member

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Glad someone is finally adding this. This flag was actually introduced in Python 3.13.

@adamjstewart adamjstewart self-assigned this Dec 1, 2025
adamjstewart
adamjstewart previously approved these changes Dec 1, 2025
@adamjstewart adamjstewart enabled auto-merge (squash) December 1, 2025 13:26
@wdconinc
Copy link
Contributor

wdconinc commented Dec 1, 2025

What will be the recommended approach for packagers here? Is anything special needed to indicate that a package supports python ~gil? Should the packaging guide include documentation on this topic?

I assume we'd have things like:

    conflicts("^python ~gil")

but that means that all packages become automatically free-threading supported instead of that needing to be affirmatively stated by the maintainer.

@wdconinc
Copy link
Contributor

wdconinc commented Dec 1, 2025

but that means that all packages become automatically free-threading supported instead of that needing to be affirmatively stated by the maintainer.

Maybe this is just my lack of understanding what the "Free Threading" classifier is intended to document:
https://pypi.org/search/?c=Programming+Language+%3A%3A+Python+%3A%3A+Free+Threading

@adamjstewart adamjstewart disabled auto-merge December 1, 2025 14:21
@adamjstewart
Copy link
Member

I think we'll have to leave it up to downstream packages to add this conflict. I suspect that most pure-Python packages will support GIL. Cython packages may need special changes. @rgommers would know more.

There are currently a lot of underspecified packages out there. We could definitely go further to scrape PyPI to add supported Python version ranges. The presence of both 3.13/3.14 and 3.13t/3.14t wheels would be strong evidence that GIL is supported, even if no tags are added.

@rgommers
Copy link
Contributor

rgommers commented Dec 1, 2025

I think it's fine to not worry about conflicts unless the build itself is actually broken (and fixing that is usually easy). Free-threading is opt-in and known to be under development, and the users who want this now do know that. It's actually quite useful to be able to build packages for a free-threading interpreter even if the package itself hasn't been made thread-safe yet or re-enables the GIL on import. Running code with PYTHON_GIL=0 python to experiment tends to work for many packages.

I'm inclined to recommend that it should not be supported for 3.13t in Spack at all. It's so much more buggy than 3.14, and lots of key libraries (cryptography, cffi, pyyaml`, etc.) will never support 3.13t. So there isn't much point in spending any effort on 3.13t anymore.

Cython packages may need special changes

Yes, Cython/C/C++/Rust-using libraries all need changes (as described at https://py-free-threading.github.io/porting/), but a decent amount of that for the most popular packages is done now (see https://hugovk.github.io/free-threaded-wheels/).

@rgommers
Copy link
Contributor

rgommers commented Dec 1, 2025

It'd be good to call the option freethreading rather than gil, as per the Python Steering Council's guidance: python/steering-council#221 (comment)

@adamjstewart
Copy link
Member

I think we can let people play around with 3.13t if they want, but I agree that we won't be trying to fix packages to make 3.13t work.

I'm fine with renaming the variant "freethreading", it's more clear to me as well.

@adamjstewart
Copy link
Member

@spackbot fix style

@spackbot-app
Copy link

spackbot-app bot commented Dec 2, 2025

Let me see if I can fix that for you!

adamjstewart
adamjstewart previously approved these changes Dec 2, 2025
Copy link
Member

@adamjstewart adamjstewart left a comment

Choose a reason for hiding this comment

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

Will give others time to review. Ping me to merge if there are no comments after a week.

@spackbot-app
Copy link

spackbot-app bot commented Dec 2, 2025

I was able to run spack style --fix for you!

spack style --fix
packages/pcl/package.py
repos/spack_repo/builtin/packages/armadillo/package.py
repos/spack_repo/builtin/packages/esmf/package.py
repos/spack_repo/builtin/packages/fcgi/package.py
repos/spack_repo/builtin/packages/flecsi/package.py
repos/spack_repo/builtin/packages/pcl/package.py
repos/spack_repo/builtin/packages/petsc/package.py
repos/spack_repo/builtin/packages/precice/package.py
repos/spack_repo/builtin/packages/py_metatensor_learn/package.py
repos/spack_repo/builtin/packages/py_metatensor_operations/package.py
repos/spack_repo/builtin/packages/py_metatensor_torch/package.py
repos/spack_repo/builtin/packages/py_metatomic_torch/package.py
repos/spack_repo/builtin/packages/py_metatrain/package.py
repos/spack_repo/builtin/packages/py_petsc4py/package.py
repos/spack_repo/builtin/packages/py_pydantic/package.py
repos/spack_repo/builtin/packages/py_pydantic_core/package.py
repos/spack_repo/builtin/packages/py_shroud/package.py
repos/spack_repo/builtin/packages/py_vesin/package.py
repos/spack_repo/builtin/packages/python/package.py
repos/spack_repo/builtin/packages/r/package.py
repos/spack_repo/builtin/packages/root/package.py
repos/spack_repo/builtin/packages/superlu/package.py
repos/spack_repo/builtin/packages/superlu_dist/package.py
repos/spack_repo/builtin/packages/velvet/package.py
repos/spack_repo/builtin/packages/xrootd/package.py
οΏ½[1;34m==> οΏ½[0mrunning flake8
repos/spack_repo/builtin/packages/python/package.py:176: [E501] line too long (109 > 99 characters)
οΏ½[1;34m==> οΏ½[0mrunning isort
οΏ½[1;34m==> οΏ½[0mrunning black
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with style fixes.

@adamjstewart
Copy link
Member

Should we add external variant detection? Does the executable name change?

@rgommers
Copy link
Contributor

rgommers commented Dec 2, 2025

Should we add external variant detection? Does the executable name change?

Not sure about the first question, but for the second: the executable name does change, it's python3.14t rather than python3.14. However, depending on the install method the plain python or python3 names may be aliased to a free-threaded interpreter. If you're only looking at the 3.xx-named ones, it should be robust.

@adamjstewart
Copy link
Member

For the first question: the context here is that spack external find ... can locate non-Spack installed packages from the system and register them in Spack's database. We can detect whether or not Python was built with +freethreading using https://docs.python.org/3/howto/free-threading-python.html#identifying-free-threaded-python. This would go in the determine_variants function.

For the second question, we currently check for pythonX.Y, pythonX, and python in that order. I would propose also adding pythonX.Yt to that list, possibly in the front.

@rgommers
Copy link
Contributor

rgommers commented Dec 3, 2025

Thanks for the context - sounds like a good plan to add that then!

@adamjstewart
Copy link
Member

@spackbot run pipeline

@spackbot-app
Copy link

spackbot-app bot commented Dec 15, 2025

I've started that pipeline for you!

@adamjstewart adamjstewart enabled auto-merge (squash) December 15, 2025 20:03
@adamjstewart
Copy link
Member

I'm testing this now and it's mostly working, although there are a ton of packages that will need updating. Many packages use the limited CPython API, which is not compatible with free-threading. This has mostly been fixed in newer versions, but not always.

@rgommers
Copy link
Contributor

I'm testing this now and it's mostly working, although there are a ton of packages that will need updating. Many packages use the limited CPython API, which is not compatible with free-threading. This has mostly been fixed in newer versions, but not always.

It's usually not hard to fix upstream. If there are packages that are important/blocking, I'm happy to help with those.

@adamjstewart adamjstewart merged commit 6677374 into spack:develop Dec 15, 2025
27 checks passed
@rgommers
Copy link
Contributor

I gave this a spin, all seems to be in order. Not all packages support free-threading or 3.14 yet, but a lot do - this built fine:

spack:
  specs:
  - [email protected]+freethreading
  - py-numpy
  - py-scipy
  - py-scikit-learn
  - [email protected]
  - py-pytest
  - py-hypothesis
  - py-cython
  - py-cffi
  - meson
  - ninja
  - py-aiohttp
  - py-pandas
  - py-pywavelets
  - py-sentencepiece
  - py-tornado
  view: true
  concretizer:
    unify: true

The main issue I ran into is too old versions being pulled in (e.g., matplotlib, swig) but that's easy to resolve when you see it.

@adamjstewart
Copy link
Member

I just submitted a bunch of PRs to fix 3.14 support. After those are merged, I'll try to get the TorchGeo deps building with 3.14t.

mkrack pushed a commit to mkrack/spack-packages that referenced this pull request Dec 23, 2025
* Added GIL removal as option

* Update repos/spack_repo/builtin/packages/python/package.py

Co-authored-by: Adam J. Stewart <[email protected]>

* Update repos/spack_repo/builtin/packages/python/package.py

Co-authored-by: Adam J. Stewart <[email protected]>

* changed ~gil to +freethreading, starting from 3.13

* [@spackbot] updating style on behalf of BaLinuss

---------

Co-authored-by: Adam J. Stewart <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants