Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

Hypothesis 现在是线程安全的

Posted on 2025-08-09

Hypothesis 现在是线程安全的

Hypothesis 是一个基于属性的 Python 测试库。它允许你编写如下测试:

从假设导入给定,策略作为  @given ( st.lists ( st.integers () ) ) def test_matches_builtin ( ls ):     断言sorted ( ls ) == my_sort ( ls )

这将自动创建一组测试用例,用于测试大量预期的列表和整数形状。以下是Gist,演示了上述代码将运行的测试,其中包括:

 [] [0] [-62, 13194] [44, -19562, 44, -12803, -24012] [-7531692443171623764, -109369043848442345045856489093298649615] Hypothesis 贡献者 Liam DeVoe 最近得到了 Quansight 的赞助,为 Hypothesis 添加了线程安全性,由于 Python 的自由线程,这一点最近变得非常重要: [] [0] [-62, 13194] [44, -19562, 44, -12803, -24012] [-7531692443171623764, -109369043848442345045856489093298649615]

虽然我们当然一直希望 Hypothesis 是线程安全的,但线程安全历来都不是优先事项,因为在多个线程下运行 Hypothesis 测试并不是我们经常看到的事情。

这种情况最近有所改变。Python——作为一种语言,同时也是一个社区——正准备在一个名为“自由线程”的版本中移除全局解释器锁 (GIL) 。Python 包,尤其是那些与 C API 交互的包,需要测试其代码是否在自由线程版本下仍然有效。一个好方法是同时在两个或多个线程中运行套件中的每个测试。[…]

Nathan 提到,由于 Hypothesis 不是线程安全的,因此在测试自由线程兼容性时必须跳过社区包中的 Hypothesis 测试,这会消除大量的覆盖范围。

现在,Hypothesis 是线程安全的,增加 Python 生态系统对自由线程支持的另一个障碍已被消除!

通过lobste.rs

标签: gil 、 python 、测试、线程

原文: https://simonwillison.net/2025/Aug/8/hypothesis/#atom-everything

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Big Technology
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • eighty twenty
  • Elad Gil
  • Ellie Huxtable
  • Ethan Dalool
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Li Haoyi
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Maggie Appleton
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mind Matters
  • Mostly metrics
  • Naval Ravikant
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Rohit Patel
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Steph Ango
  • Stephen Wolfram
  • Steve Blank
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • Wes Kao
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme