What happened?
Since gh-145685, a static type defined in an extension module keeps a single attribute cache (type->_tp_cache) that every interpreter uses; only static builtin types get a per-interpreter one (cache_slot() in Python/typecache.c). Once the main interpreter has used such a type, attribute lookups on it from an isolated subinterpreter crash. With the stdlib's xxsubtype on a --with-pydebug build:
from concurrent import interpreters
import xxsubtype
xxsubtype.spamlist().append(1)
interp = interpreters.create()
interp.exec("import xxsubtype\nfor n in dir(xxsubtype.spamlist): getattr(xxsubtype.spamlist, n)")
interp.close()
print("ok")
$ ./python repro.py 2>/dev/null; echo "exit=$?"
exit=139
On the free-threaded build, concurrent lookups on the same type from two interpreters also corrupt the heap.
Expected: ok, as on 3.15.
I can open a PR with either fix: (a) not using the per-type cache for static types that are not static builtins, or (b) storing their caches per interpreter, as static builtin types already do. Let me know which you prefer.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.16.0a0 (remotes/upstream/HEAD:a000129df30, Sep 25 2026, 21:52:46) [GCC 15.2.0]
What happened?
Since gh-145685, a static type defined in an extension module keeps a single attribute cache (
type->_tp_cache) that every interpreter uses; only static builtin types get a per-interpreter one (cache_slot()inPython/typecache.c). Once the main interpreter has used such a type, attribute lookups on it from an isolated subinterpreter crash. With the stdlib'sxxsubtypeon a--with-pydebugbuild:On the free-threaded build, concurrent lookups on the same type from two interpreters also corrupt the heap.
Expected:
ok, as on 3.15.I can open a PR with either fix: (a) not using the per-type cache for static types that are not static builtins, or (b) storing their caches per interpreter, as static builtin types already do. Let me know which you prefer.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.16.0a0 (remotes/upstream/HEAD:a000129df30, Sep 25 2026, 21:52:46) [GCC 15.2.0]