- https://github.com/pfalcon/micropython- ... r/uasyncio
- https://pypi.org/project/micropython-uasyncio/
Content below traces the evolution of uasyncio and may contain outdated information.
============================================
This thread is intended to be continuation of ticket #242 RFC: Cooperative concurrency model of choice for MicroPython. If you're interested in this topic, please make sure you read that ticket, as it contains a lot if insightful references and comments.
So, with "yield from" having been implemented in MicroPython, I proceeded to learn more about CPython's asyncio library, while concurrently trying to write something similar, but strictly unbloated. My prototyping work is in branch of micropython-lib: https://github.com/pfalcon/micropython-lib/tree/asyncio . After some experimenting, I got serious concerns that "asyncio" and "unbloated" don't go together. My questioning and criticism of some asyncio traits are available here: https://groups.google.com/forum/#!topic ... fMQIUcIR-0
My conclusion from that research is that CPython's asyncio doesn't have initial requirements which would match those of MicroPython. While primary requirements for MicroPython modules are minimal memory and CPU cycles usage, which necessitates usage of builtin Python features (like coroutines), while the primary requirement for CPython's asyncio is to provide "least common denominator" foundation to allow all previously existing Python async frameworks to cooperate. This "least common denominator" is of course completion callbacks. So, asyncio starts with them, and adds layer after layer until it finally gets to supporting coroutines. Implementing it in such way on MicroPython would mean lots of memory wasted for these intermediary representations.
As outcome of the prototyping, there're 2 implementations:
- https://github.com/pfalcon/micropython- ... yncio_slow - this follows official asyncio API, but features naive polling scheduling, and doesn't support any I/O.
- https://github.com/pfalcon/micropython- ... ncio_micro - this takes asyncio API as the basis, but centered around coroutine support. It features priority (time) queue scheduler and has support for I/O scheduling.
But per the description above, I don't intend to continue working on it, and instead going to concentrate on asyncio_micro. I just made a trivial HTTP server example work with it, so there're lot of issues to resolve before it will be stable.
Comments, contribution, testing - all welcome!