Add Virtual Threads to Python

I’m a little confused as to the goals of “virtual threads”. If they’re supposed to function like normal threads and “just work”, and not demand function colouring, then they should preempt just like regular threads do; and if that’s the case, their semantics would be identical to regular threads. In other words, this wouldn’t be a new API, it would simply be a change [1] to the threading module to use virtual threads rather than OS threads, giving a performance improvement.

But if they are to “only switch execution at well defined points in the code”, how can that be done without function colouring? Either a function has such well-defined points in it, or it doesn’t. Or is it that every function becomes red under this plan, and thus all code pays a price for the mere existence of virtual threads, even if it doesn’t use them?

Sorry if this is a dumb question.


  1. possibly an optional change ↩︎

20 Likes