uasyncio - 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.
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pythoncoder » Thu Dec 28, 2017 9:25 am

Alas I have no experience of using _thread under MicroPython so I can't comment on performance. I avoid pre-emptive scheduling if I possibly can. I think my approach would be to try to include the C modules in the build in an attempt to get uasyncio working. I don't know how easy that would be, mind you, but it's surely worth a try.

Failing that there is my old scheduler which is written entirely in Python. I should stress that I regard this as obsolete: I wrote it as my first MicroPython project before I had any knowledge of optimisation techniques. However it does work. My touch GUI's used it until I ported them to uasyncio so it has performance adequate to support a UI in a typical application. If you adopt that approach and the team at Pycom subsequently wake up and smell the coffee that is uasyncio, porting your application to it should be straightforward.
Peter Hinch
Index to my micropython libraries.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by Roberthh » Thu Dec 28, 2017 10:21 am

I made the attempt to port the module utimeq into the Pycom MP variant (instructions here: https://github.com/pycom/pycom-micropyt ... issues/112) and also made a PR to fix their utime module (https://github.com/pycom/pycom-micropyt ... x/pull/115). That allows using asyncio on Pycom MP, after catering for sligtly different API calls, like reversed arguments of utime.ticks_diff(), and the missing poll.ipoll() method. I tried some of the uasyncio examples. They seem to work.
The port of utimeq seems to have many places to change, but most of that is simple management and settings. I di dnot make a PR for that yet, but could do so.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pythoncoder » Fri Dec 29, 2017 7:35 am

@Roberthh Well done!

Pycom must be using ancient code: the ticks_diff() argument order was changed well over a year ago. That will cause a lot of applications developed for normal MicroPython targets to fail on their products :(
Peter Hinch
Index to my micropython libraries.

User avatar
on4aa
Posts: 70
Joined: Sat Nov 11, 2017 8:41 pm
Location: Europe
Contact:

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by on4aa » Fri Dec 29, 2017 8:33 am

@Roberthh Wow, that is truly impressive!

I only hope Pycom understands and appreciates what you have achieved.
Last edited by on4aa on Mon Jan 22, 2018 11:28 pm, edited 1 time in total.
Serge

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

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pfalcon » Sat Jan 06, 2018 11:21 am

Note that the latest uasyncio packages on PyPI require the latest MicroPython, built from source. I no longer a comaintainer of the (official) MicroPython, and don't influence when upstream releases are made.

I also test uasyncio with my fork, https://github.com/pfalcon/micropython , and in the future may imagine that it may work only with my fork.

In my fork, I continue development and optimization of uasyncio and other MicroPython-related components, which I no longer can perform in the upstream.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

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

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pfalcon » Sun Jan 07, 2018 8:48 am

uasyncio.cancel(coro) has been implemented in uasyncio.core 1.7.1. It corresponds to asyncio's Task.cancel() method (as there's no "Task" wrapper in uasyncio, it instead goes as a top-level function which accepts native coroutine object).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

uasyncio.cancel(coro)

Post by pythoncoder » Sun Jan 07, 2018 11:58 am

I've found this on PyPI but not in micropython-lib - will future changes appear there?
Peter Hinch
Index to my micropython libraries.

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

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pfalcon » Sun Jan 07, 2018 2:26 pm

Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

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

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pfalcon » Sat Feb 03, 2018 2:49 pm

uasyncio 2.0 is coming up. It switches scheduling to 2-level algorithm, which requires asymptotically less memory, and allows to repurpose existing memory overheads to resolve other pending issues in asyncio. It will depend on the functionality in https://github.com/pfalcon/micropython .
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

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

Re: uasyncio - asyncio-like cooperative multitasking framework for uPy

Post by pfalcon » Tue Feb 06, 2018 10:33 pm

Ok, uasyncio.core 2.0/uasyncio 2.0 were released, with scheduling optimizations which should enable even more optimizations in the future. uasyncio.core now depends on ucollections.deque class implemented in https://github.com/pfalcon/micropython .
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply