Skip to content

Free threaded - #23437

Closed
ndellosa95 wants to merge 7 commits into
pantsbuild:mainfrom
ndellosa95:free-threaded
Closed

Free threaded#23437
ndellosa95 wants to merge 7 commits into
pantsbuild:mainfrom
ndellosa95:free-threaded

Conversation

@ndellosa95

Copy link
Copy Markdown
Contributor

yeet

@tobni

tobni commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

In its current iteration this change increases runtime by about 4x but increases core-engagement by about +5 on my 8 core machine. I'm investigating why.

@tobni

tobni commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

#23477

@ndellosa95

Copy link
Copy Markdown
Contributor Author

Closed in favor of #23477

@ndellosa95 ndellosa95 closed this Jul 6, 2026
tobni added a commit that referenced this pull request Aug 9, 2026
Switches Pants' own runtime to free-threaded CPython and makes the
engine and
Pants' Python code thread-safe without the GIL.

This has been validated as running without error in my companies CI, and
nets great speedups.

Most important callouts:
- Keep a persistent per-thread PyThreadState in the executor. Without
this, every `Python::attach` cycle tears down the thread state, and on
3.14t
that abandons the thread's mimalloc heaps. Created per tokio thread,
torn down in `on_thread_stop` (blocking
  threads are recycled, so the state must not leak per thread creation).
- Makes run-scoped internals thread-safe: rule_visitor, exception_sink,
logging, build_root, run_tracker.

I used #23437 as a launching
point.

I have on speculation set this as shipping in 2.34.x, as I believe 2.33
is too far along the dev-cycles. But I also do not see any reason to
delay further.

Blocks pantsbuild/scie-pants#541

Edit:
This branch now serves as proof of green CI of the accumulation of
changes, and will be rebased as its parts are accepted incrementally:
- #23487
- #23488
- #23489
- #23490
- #23491
- #23492
- #23497
- #23514

Edit2:

Now that all pre-requisites are in, this PR contains CI/CD changes and
the new PANTS_FREE_THREADED option.
Current proposal for consumer UX is

| Consumer | `pants.toml#[GLOBAL].pants_free_threaded` | Resolves to |
Bootstrap warning |
|---|---|---|---|
| **scie-pants - not updated** | absent / `false` | `cp314` (GIL 3.14) |
- |
| **scie-pants - not updated** | `true` | `cp314` (GIL 3.14) | **"update
scie-pants"**. Old launcher can't honor the field |
| **scie-pants - updated** | absent (default) | `cp314t` (free-threaded)
| - |
| **scie-pants - updated** | `false` | `cp314` (GIL 3.14) | - (escape
hatch) |
| **scie-pants - updated** | `true` | `cp314t` (free-threaded) | - |
| **Fat scie - `…-cp314`** | `true` | GIL 3.14 | **"no effect on a fat
scie; download the binary you want"** |
| **Fat scie - `…-cp314t`** | `false` | free-threaded | **"no effect on
a fat scie; download the binary you want"** |

This PR is coupled to pantsbuild/scie-pants#541.
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