Debian Codegraph @

website/content/2025-08-07-thread-safe.md

raw symbols SCIP
1 ---
2 date: 2025-08-07 00:00
3 title: Hypothesis is now thread-safe
4 author: liam
5 ---
6
7 *TL;DR: as of [version 6.136.9](https://hypothesis.readthedocs.io/en/latest/changelog.html#v6-136-9), Hypothesis supports running the same test simultaneously from multiple threads.*
8
9 Hypothesis has historically had the following thread-safety policy:
10
11 * Running tests in multiple processes: fully supported.
12 * Running separate tests in multiple threads: not officially supported, but mostly worked.
13 * Running the same test in multiple threads: not supported, and didn't work.
14
15 No longer! In a series of releases spanning from [v6.135.17](https://hypothesis.readthedocs.io/en/latest/changelog.html#v6-135-17) to [v6.136.9](https://hypothesis.readthedocs.io/en/latest/changelog.html#v6-136-9), Hypothesis has gained official support for all three of these cases. You can read about the details of what we now guarantee [here](https://hypothesis.readthedocs.io/en/latest/compatibility.html#thread-safety-policy). The now-historic tracking issue is [here](https://github.com/HypothesisWorks/hypothesis/issues/4451).
16
17 ## Why now?
18
19 While we of course would always have loved for Hypothesis to be thread-safe, thread-safety has historically not been a priority, because running Hypothesis tests under multiple threads is not something we see often.
20
21 That changed recently. Python—as both a language, and a community—is gearing up to [remove the global interpreter lock (GIL)](https://peps.python.org/pep-0703/), in a build called [free threading](https://docs.python.org/3/howto/free-threading-python.html). Python packages, especially those that interact with the C API, will need to test that their code still works under the free threaded build. A great way to do this is to run each test in the suite in two or more threads simultaneously.
22
23 Where does Hypothesis fit into this? When I was at [PyCon 2025](https://us.pycon.org/2025/) in May earlier this year, I talked with [Nathan Goldbaum](https://github.com/ngoldbaum) from [Quansight](https://quansight.com/), who is one of the people working on community free threading compatibility. Nathan mentioned that because Hypothesis is not thread-safe, Hypothesis tests in community packages have to be skipped when testing free threaded compatibility, which removes a substantial battery of coverage.
24
25 As a result, Quansight contracted me to work on making Hypothesis thread-safe. I enjoy contributing to Hypothesis in my free time even without a monetary incentive, so this was a pleasure to do, and Nathan and Quansight were great to work with. (Seriously: it's thanks to them funding my time that Hypothesis is now thread-safe!)
26
27
28 ## A note on compatibility
29
30 Free threading may have been the impetus for making Hypothesis thread-safe, but the thread-safety of Hypothesis is not tied to it. Even in the unlikely event that free threading is rolled back tomorrow by the Steering Council, Hypothesis will continue to remain thread-safe.
31
32 Now, go forth and run Hypothesis in parallel!