asyncio-like cooperative multitasking framework for uPy

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
pfalcon
Posts: 902
Joined: Fri Feb 28, 2014 2:05 pm

asyncio-like cooperative multitasking framework for uPy

Postby pfalcon » Sat May 03, 2014 9:41 pm

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/micropython/micropyt ... ee/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:


asyncio_slow was written as an exercise to understand asyncio way of doing things better. It also captures a simple scheduler, which show how easy it is to write a coroutine scheduler with system services support with the help of "yield from". I decided that these 2 features are enough to keep it in the repo and not throw away.

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!

nelfata
Posts: 74
Joined: Wed Apr 30, 2014 10:50 pm

Re: asyncio-like cooperative multitasking framework for uPy

Postby nelfata » Thu May 08, 2014 1:07 am

Hi,
I saw your not regarding asyncio.
My question is not so related, but I am trying to get a webserver working on my board, but after connecting the WiFi module I am not able to get a connection going. If you were able to get the Adafruit CC3000 working, could you please share your thoughts? code?

Thank you.

User avatar
fma
Posts: 156
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: asyncio-like cooperative multitasking framework for uPy

Postby fma » Wed May 14, 2014 7:03 am

Hi!

I'm totally new to coroutines, asyncio and so... I only used thread so far, but it seems that they are things of the past! So, I started looking at CPython asyncio module, and I will try to switch one of my project to asyncio, as I would like to port it to micropython.

But I understood that asyncio-micro will be a little bit different; while working on it, could you make a wiki page showing the main differences? I guess there will be some feature that won't be supported at all, due to micropython architecture, and it would be interesting to know which ones, to avoid using them with CPython...

Thanks for the great work provided on this wonderfull project!
Frédéric

pfalcon
Posts: 902
Joined: Fri Feb 28, 2014 2:05 pm

Re: asyncio-like cooperative multitasking framework for uPy

Postby pfalcon » Tue May 20, 2014 2:03 pm

fma, I'm maintaining few wiki pages, and those need some love first, before starting new ones. So instead, I started this thread which should be better to track work-in-progress. So far, the best way to see the differences is to look at tests/examples available in https://github.com/micropython/micropyt ... ncio_micro , they are based on similar examples for CPython asyncio docs. For motivation of differences, this thread should provide some insight and further pointers, and I'll be glad to discuss them in-depth if there're questions/ideas. I hope to do more posts myself as time permits.

pfalcon
Posts: 902
Joined: Fri Feb 28, 2014 2:05 pm

Re: asyncio-like cooperative multitasking framework for uPy

Postby pfalcon » Wed Aug 27, 2014 9:25 pm

The module has been renamed to "uasyncio" to follow emerging convention of modules whose grand idea comes from CPython's modules, but which have optimized implementation which calls for somewhat different API. The module is still in a separate branch, I'm calling other uPy developers to decide whether it should be merged to micrpython-lib's master or separated as a 3rd-party package.

User avatar
fma
Posts: 156
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: asyncio-like cooperative multitasking framework for uPy

Postby fma » Thu Aug 28, 2014 6:02 am

I'm not a micropython developper, but I vote for a merge to micropython-lib, as asyncio routines seems to be an important part of multitasking dev using coroutines, which is the only way under micropython...
Frédéric

User avatar
fma
Posts: 156
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: asyncio-like cooperative multitasking framework for uPy

Postby fma » Fri Aug 29, 2014 1:56 pm

BTW, where is uasuncio, now? I would like to make some tests, even if it is not the final version... Thanks.
Frédéric


User avatar
fma
Posts: 156
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: asyncio-like cooperative multitasking framework for uPy

Postby fma » Fri Aug 29, 2014 4:54 pm

Thank you.
Frédéric

pfalcon
Posts: 902
Joined: Fri Feb 28, 2014 2:05 pm

Re: asyncio-like cooperative multitasking framework for uPy

Postby pfalcon » Fri Aug 29, 2014 8:47 pm

fma wrote:BTW, where is uasuncio, now? I would like to make some tests, even if it is not the final version... Thanks.


Well, it's dubbed version 0.6 now: https://pypi.python.org/pypi/micropython-uasyncio . I didn't make changes to it in a while and it allows to run a web framework on top if itself, that's why I'm raising the question of merging it to the master of micropython-lib. Surely, it could use more peer review and testing. In particular I didn't try to run it on Pyboard (only on unix port), and would appreciate any reports on that.


Return to “Programs, Libraries and Tools”

Who is online

Users browsing this forum: No registered users and 2 guests