Skip to content

Add free-threaded Python (3.14t) support#379

Merged
cjrh merged 5 commits intomainfrom
add-free-threaded-python
Mar 30, 2026
Merged

Add free-threaded Python (3.14t) support#379
cjrh merged 5 commits intomainfrom
add-free-threaded-python

Conversation

@cjrh
Copy link
Copy Markdown
Owner

@cjrh cjrh commented Mar 30, 2026

Summary

  • Add Python 3.14t (free-threaded / no-GIL) to the CI matrix, with PYTHON_GIL=0 to ensure the GIL stays disabled during testing
  • Fix thread-safety issues in pool management that were hidden by the GIL:
    • busy_workers set accessed from multiple run_task threads without synchronization
    • existing_workers and running_futs WeakSets (not thread-safe without GIL)
    • max_workers_busy_concurrently stat had a read-then-write race condition

All fixes use a single _workers_lock since the protected operations are brief and closely related.

tasks_ran_counter and worker.ok were analyzed and found to be single-owner (each WorkerProcess is exclusively held by one thread at a time), so no locks needed there.

Test plan

  • All 65 tests pass locally on free-threaded Python 3.14t
  • No SyntaxWarning on import with 3.14t
  • psutil and setproctitle both have cp314t wheels
  • CI passes for all matrix entries including 3.14t

cjrh and others added 5 commits March 30, 2026 16:27
Add Python 3.14t (free-threaded, no-GIL) to the CI matrix with
PYTHON_GIL=0 to ensure the GIL stays disabled during testing.

Fix several thread-safety issues in pool management that were
previously hidden by the GIL:
- Protect busy_workers set with a lock (concurrent add/remove/len
  from multiple run_task threads)
- Protect existing_workers and running_futs WeakSets (not
  thread-safe without GIL)
- Fix max_workers_busy_concurrently race condition (read-then-write
  without holding the stat's lock)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The free-threaded build installs as python3.14t, not python3.14,
so nox can't find it via its default discovery. Use --force-python
to tell nox to use the current interpreter directly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Nox >= 2025.10.14 supports 3.14t in session python lists natively,
so add it to the nox sessions and use nox -s testcov-3.14t directly
instead of working around the interpreter discovery.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The test expected exactly 11 unique PIDs, but PID recycling can
cause a replaced worker to get the same PID as its predecessor,
reducing the count. Use >= 10 which still proves worker replacement
is happening while tolerating occasional PID reuse.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cjrh cjrh merged commit ac2563f into main Mar 30, 2026
15 checks passed
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.

1 participant