Thread-safety and Hypothesis (original) (raw)
Python is working towards removing the global interpreter lock, in a python build version called free-threading. As the free-threading build is actively under development, one of the primary ways to flush out semantic errors and concurrency bugs (inside both free-threading itself, and the python ecosystem) is by running test suites of open-source repositories in parallel, with e.g. pytest-run-parallel.
Hypothesis is not thread safe, which we document in our thread-safety policy. This is unfortunate for testing free-threading, because many repositories include Hypothesis tests, which must be skipped when using pytest-run-parallel.
As a result, after talking with @ngoldbaum at PyCon 2025 about free-threading, @Quansight has contracted me to work on making Hypothesis thread-safe ❤. I think this will be great for helping move free-threading forward as an ecosystem.
I'll use this issue to track our progress towards thread-safety. If you're interested in getting progress updates yourself, click 'follow' on this thread! I'll post as major improvements occur.
Followup notes
- update our thread safety docs
- As a future extension, we might want to issue a healthcheck warning for any use of the global Random instance on a free-threading build. Make deprecate_random_in_strategy thread safe #4453 (review)