Use of gc.get_referrers() in register_random breaks in free-threaded CPython 3.13 #3965
Labels
interop
how to play nicely with other packages
legibility
make errors helpful and Hypothesis grokable
See python/cpython#118522 for where I initially thought this was a CPython bug.
In the Python 3.13 free-threaded build, the current plan is for certain objects to be marked as immortal if any threads are created at runtime. See python/cpython#117783. In Python 3.14 these objects will be reference counted using a deferred reference counting strategy.
This change in Python 3.13 breaks the check in
register_randombased ongc.get_referrers(). You can reproduce this by first setting up a free-threaded build of python 3.13 (see https://github.com/quansight-labs/free-threaded-compatibility for more details on setting up a python 3.13 free-threaded dev environment) and then applying the following patch to a checkout of the numpy repo:You can then execute the test with
And you'll see the warning about an RNG possibly getting garbage collected spuriously raised for hypothesis' own default global RNG instance:
I think maybe the easiest fix is to add an additional check like the one that's already there for pypy for the free-threaded python build. Note that this behavior will only happen if a thread is spawned before the RNG is registered, so the behavior of this function will be impacted by whether or not unrelated code spawned a thread.
The text was updated successfully, but these errors were encountered: