Visitar URL original
Python 3.14 free-threaded support by greateggsgreg · Pull Request #2721 · pythonnet/pythonnet · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d93b30
Thread-safety prep for free-threading builds
greateggsgreg May 9, 2026
e029137
Initialise pythonnet on free-threaded Python (#2720)
greateggsgreg May 9, 2026
fd56aa4
Make extension/CLR-object registries thread-safe
greateggsgreg May 9, 2026
b727a15
Atomic type creation in ReflectedClrType.GetOrCreate / TypeManager.Ge…
greateggsgreg May 9, 2026
debba0d
Add free-threaded thread-stress tests and 3.14t to CI matrix
greateggsgreg May 9, 2026
585916e
Atomic GCHandle ownership and finalizer-thread shutdown guards
greateggsgreg May 10, 2026
c0ddb29
Make additional internal registries thread-safe
greateggsgreg May 10, 2026
096e466
test_thread: join worker threads before returning
greateggsgreg May 10, 2026
5005f36
test_thread: cover ModuleObject thread-safe registries
greateggsgreg May 10, 2026
3ad586a
Wider thread-safety audit fixes for free-threaded Python
greateggsgreg May 10, 2026
6b1f3f4
Document lock acquisition sites and strong->weak GCHandle swap
greateggsgreg May 10, 2026
732d97e
Preserve InternString single-write invariant under DEBUG
greateggsgreg May 10, 2026
3d56611
test_thread: cover real-world consumer patterns
greateggsgreg May 10, 2026
7094b12
Auto-detect free-threaded libpython in venv home
greateggsgreg May 12, 2026
f49ed1b
Snapshot pypath, use ConcurrentDictionary for thunks and slot holders
greateggsgreg May 13, 2026
fa89ff0
Fix handling of python runtime suffixes m/t
greateggsgreg May 13, 2026
a373e79
Fix threadtest race
greateggsgreg May 13, 2026
43a4237
Fix double-free in chained ClassDerived Finalize
greateggsgreg May 13, 2026
b42377e
Enable Mono CI jobs on free-threaded Python 3.14
greateggsgreg May 13, 2026
526a297
Inline freethreaded_only as pytest.mark.skipif at call sites
greateggsgreg May 13, 2026
8485837
Fix InterruptTest assertion on free-threaded Python 3.14
greateggsgreg May 13, 2026
a459772
Add concurrent stress tests for PyBuffer.Dispose and CLR-cycle gc.col…
greateggsgreg May 15, 2026
3bf6d68
Trim concurrent overhead on hot paths from free-threading prep
greateggsgreg May 15, 2026
3433446
Pre-warm ctor binder in concurrent-gc test to avoid first-call race
greateggsgreg May 15, 2026
4a034f7
Make MethodBinder.GetMethods lazy init thread-safe under free-threading
greateggsgreg May 15, 2026
afd5799
Precompute method precedence to avoid quadratic GetParameters allocat…
greateggsgreg May 15, 2026
95e4811
Zero the slot in ClassDerived.tp_dealloc when tp_clear already ran to…
greateggsgreg May 15, 2026
a799c44
Keep ClassDerived wrapper alive across the NewObjectToPython slot dem…
greateggsgreg May 15, 2026
220b4b4
Document private helpers added during free-threading prep
greateggsgreg May 16, 2026
dfda807
Add debug echoes and a 6-minute step timeout to the Mono test job
greateggsgreg May 16, 2026
1130f6a
Drop the per-loop CLR GC.Collect from concurrent-gc test to avoid Mon…
greateggsgreg May 16, 2026
f75cbab
Add temporary Mono-step diagnostics on Linux/macOS to locate the x64-…
greateggsgreg May 16, 2026
64ea342
Revert temporary Mono-step diagnostics now that the underlying race i…
greateggsgreg May 16, 2026
fda8211
Add user-facing threading guide covering GIL, free-threading, and com…
greateggsgreg May 18, 2026
356d76f
Harden CollectBasicObject against .NET-GC timing differences
greateggsgreg May 18, 2026
f0ee4b2
Adjust the header offset on 32bit systems
filmor Aug 21, 2026
3445b08
Drop broken and unnecessary exclude
filmor Aug 22, 2026
8e6861e
Be strict about not loading on Python 3.13
filmor Aug 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_thread: cover ModuleObject thread-safe registries
Two tests for the thread-safe-collections work in 0a9d482:

- test_module_dunder_all_added_once asserts ModuleObject.allNames keeps
  add-once semantics; a torn HashSet would surface duplicates in
  __all__ on free-threaded builds.
- test_concurrent_module_attribute_access exercises ModuleObject.cache
  with concurrent getattr on a CLR namespace.  The old plain Dictionary
  threw on Add ("duplicate key") under simultaneous misses; the
  ConcurrentDictionary version absorbs the race.

Both run on every interpreter (no @freethreaded_only) — they degenerate
to single-threaded smoke checks under the GIL while the FT build
actually exercises contention.
  • Loading branch information
greateggsgreg authored and filmor committed Aug 18, 2026
commit 5005f3632d391e211bdfdce92ed7d8733d1d7233
36 changes: 36 additions & 0 deletions tests/test_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ def test_is_gil_enabled_attribute_present_on_3_13_plus():
assert isinstance(sys._is_gil_enabled(), bool)


def test_module_dunder_all_added_once():
"""Module.__all__ adds each name exactly once.

Exercises ModuleObject.allNames (ConcurrentDictionary) — the per-name
"have we surfaced this in __all__ yet" guard. A torn HashSet would let
duplicates slip through here on free-threaded builds.
"""
import System

names = list(System.__all__)
assert len(names) == len(set(names))


def _run_in_threads(target, n_threads, *args, **kwargs):
"""Run target() in n_threads threads, return results in start order, raise on first error."""
results = [None] * n_threads
Expand Down Expand Up @@ -148,6 +161,29 @@ def access(_):
assert all(_run_in_threads(access, n_threads=8))


def test_concurrent_module_attribute_access():
"""Concurrent CLR-namespace attribute access — exercises ModuleObject.cache.

Each lookup of `System.X` either hits ModuleObject.cache or populates it
on first miss. A plain Dictionary tore on simultaneous TryGetValue/Add
from multiple threads; the test reads many distinct names per worker.
"""
import System

names = (
"String", "Int32", "Int64", "Double", "Boolean", "Object",
"DateTime", "TimeSpan", "Type", "Array", "Console", "Math",
)

def lookup(_):
for _ in range(200):
for n in names:
getattr(System, n)
return True

assert all(_run_in_threads(lookup, n_threads=8))


@freethreaded_only
def test_concurrent_clr_object_creation():
"""Concurrent CLR object alloc/free — exercises reflectedObjects + loadedExtensions.
Expand Down