Real Multithreading is Coming to Python - Learn How You Can Use It Now
Date: 5/16/2023 · Tags: #pythonSimon Willison introduces 1 an article 2 about how to use Multithreading 3 feature in latest Python mainline.
Martin Heinz provides a detailed tutorial on trying out the new Per-Interpreter GIL feature that’s landing in Python 3.12, which allows Python code to run concurrently in multiple threads by spawning separate sub-interpreters, each with their own dedicated GIL.
It’s not an easy feature to play with yet! First you need to compile Python yourself, and then use APIs that are generally only available to C code.
As he mentioned, there is also an implementation of RecvChannel
and
SendChannel
classes to create channels for exchanging data (?) which fits
Armin's prediction.
My strong hunch is that the GIL does not need removing, if a) subinterpreters have their own GILs and b) an efficient way is provided to pass (some) data between subinterpreters lock free and c) we find good patterns to make working with subinterpreters work.
-- Armin Ronacher (@mitsuhiko) 4
PS: I'm also planning a framework inspired from Actor model for multithreading Python. Working on that 😭.