From my reading of the recent posts this seems to be what people want:
- get rid of function colouring
- VirtualThread’s seem (correct me if I’ve got this wrong) to be cooperatively scheduling within a CPU thread, and preemptively scheduling on multiple CPU threads, and this behaviour is desired
- python thread synchronisation primitives which are VirtualThread compatible
- whatever is done should maximise compatibility with existing libraries
- whatever is done should keep cross-and future- platform maintenance down
There’s two approaches which exist, both of which tackle the function colouring issue:
greenlets provides a thread safe coroutine framework. Switches between coroutines are achieved by copying sections of C stack to and from the heap, and assembler fragments.
jonathanroach/cpython-await-anywhere adapts the asyncio system to avoid the need for await myfunc() and async def and other async primitives. Switches between coroutines (asyncio.Tasks) are achieved by managing the C stack as a heap, and setjmp() & longjmp().
greenlets is well understood, with a number of client frameworks, such as gevent and eventlet, which provides plug-in alternative, greenlet-aware synchronisation and communication classes.
jonathanroach/cpython-await-anywhere, as it is asyncio adapted, retains all the support of libraries for asyncio, and all the tools built into asyncio.
However, as far as I know, greenlet hasn’t gained significant traction with the higher level libraries, such as Django. Django has gone in the direction of asyncio, probably because of ASGI.
greenlet does have the downsides of needing assembler fragments, a platform support cost, additional coroutine switch costs from the stack copying, and it is another, different system for Python users to understand.
jonathanroach/cpython-await-anywhere has the hidden limit (as implementation at time of writing) of the coroutine stacks being limited to a thread’s C stack space, being new and untested, and each Task stays in one thread and using asyncio synchronisation.
I’m happy push forward with jonathanroach/cpython-await-anywhere to remove the stack space limit, provide thread & Task aware synchronisation, and multi-thread-scheduled Tasks (ie multi-thread asyncio) if that’s what people want.
This feature set, I think, would give VirtualThread functionality to asyncio, not another new system, high compatibility with existing libraries, and low/no platform support overhead.
What are people’s thoughts?