Add Virtual Threads to Python

The biggest issue I see is if you’re using regular GIL a single blocked function still brings you back to zero, and has the same limitation as asyncio. If you’re using free-threaded, the biggest advantage is you can build true work-stealing. Threads that get blocked can have their stackful functions that are stalled, stolen by other threads, which keep everything running smoothly.

I think if this is to be done, then you might as well go for the full thing. Otherwise, its just another gevent. I did do some work on this myself. I designed an extension for CPython that adds M:N stackful functions for free-threaded Python. It gives you almost the whole thing. However, because the allocator for Python objects gets tied to the thread that it starts in, when you try to resume work on another thread (work stealing) then it will just crash. So a patch to CPython is still needed.

I wrote about this more here: Making Python networking competitive with Go using work-stealing

1 Like