stackless-dev/stackless

Add support for PEP 567 context variables to tasklets

akruis opened this issue · 4 comments

Python 3.7 added the context variables and the module contextvars. See PEP 567 for details.

Using tasklets it is possible to decorate a plain old callable as a coroutine (and vice versa). To make such a coroutine fully compatible with C-Python asyncio tasklets should support PEP 567 context variables. In C-Python the current context is a property of the thread state, that is, each thread has its own current context. In Stackless Python a thread can have multiple tasklets. Therefore the current context must become a property of the tasklet.

I'm still elaborating details.

First usable code is in https://github.com/akruis/cpython/tree/slp37 (a71d969f06). It is still work in progress.
And here is the project, that needs the contextvar support https://github.com/akruis/slp_coroutine. This project is also work in progress.

Implemented in 3.7-slp

Merged into main-slp.