Behind the Commit podcast

Testing Free-Threaded Python: Larry Hastings on Race Conditions

0:00
20:42
15 Sekunden vorwärts
15 Sekunden vorwärts

In this episode, I'm chatting with Larry Hastings — CPython core developer, release manager for Python 3.4 and 3.5, creator of the Gilectomy (an attempt to remove the GIL years before free-threaded Python), and the person who added = inside f-strings and Argument Clinic to CPython. Free-threaded Python is arriving, and threaded code is hard to test: if four threads grab a lock, you don't know which one gets it first, so a race condition that shows up once in a thousand runs almost never shows up in your test suite. We talk about why the Gilectomy got slower with every core he added, Guido's bar for removing the GIL, and Blanket, Larry's library that makes threading tests deterministic. He also explains how he built it with AI doing most of the typing, and why he still reviews every line.

Outline

0:00 Meet Larry Hastings: from the Gilectomy to free-threaded Python

0:57 Brett Cannon: 'Larry, do you want to be a core developer?'

2:14 Free-threaded Python ships: what's different from 10 years ago?

2:54 Why the Gilectomy failed: reference counting across threads

3:54 More cores, slower Python

4:49 Guido's bar for removing the GIL (and does free threading clear it?)

5:43 How do you test free-threaded code?

7:05 Four threads, one lock: which one gets it first?

8:53 100% coverage vs a race condition that happens 1 in 1,000 runs

9:26 How Blanket lets your test decide which thread wins

10:08 The hardest part wasn't technical: designing the API

12:41 'The GIL is a pair of crutches we need to throw away'

14:25 Advice for code meeting free-threaded Python for the first time

15:26 Pass your locks in as parameters (nobody likes monkey patching)

16:14 Human-guided AI development: how Blanket was built

17:06 AI's bad habits: 'I'm going to write a while loop and poll'

17:38 Not vibe coding: pair programming with AI

18:27 One session writes the proposal, two more review it

19:47 Vibe-documented: 'make it sound like I wrote it'

Episode links

– Blanket on GitHub: https://github.com/larryhastings/blanket

– Blanket on PyPI: https://pypi.org/project/blanket/

– Larry Hastings on GitHub: https://github.com/larryhastings

– Guido's Artima blog post on removing the GIL: https://www.artima.com/weblogs/viewpost.jsp?thread=214235

Weitere Episoden von „Behind the Commit“