uasyncio

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

uasyncio

Post by pythoncoder » Sat Jul 07, 2018 11:21 am

I have updated my uasyncio repo. These are the main changes, prompted by the recent addition of io.IOBase.
  • Tutorial now includes details of how to use io.IOBase to write device drivers.
  • Added an "under the hood" doc which attempts to explain how uasyncio works.
  • Added a fast_io version of uasyncio containing some pending changes plus extra comments to aid understanding of uasyncio.
Pending changes in this version:
  • Fixes a bug whereby bidirectional stream devices (such as UARTS) can fail.
  • Throws an exception rather than silently failing if (e.g.) CreateTask is called incorrectly (a common error).
  • Provides an optional facility to schedule I/O at high priority.
The last of these supersedes my asyncio_priority solution. It enables the same capability of running selected devices at high priority, but in a considerably more efficient manner (owing to io.IOBase). It also means that the API is changed in only one place: initialisation of the event loop. This means that applications and drivers are written in standard MicroPython. To switch between official and fast_io version requires no code changes. To use the latter's priority I/O facility requires just one line to be amended.

The ability to write I/O device drivers in Python is a major improvement and eliminates the need for the ad hoc API changes in aysncio_priority. It also provides more efficient polling by means of the select mechanism. Finally stream I/O can be applied to devices not normally considered to be streaming devices: I have included examples.
Peter Hinch

kevinkk525
Posts: 90
Joined: Sat Feb 03, 2018 7:02 pm

Re: uasyncio

Post by kevinkk525 » Sat Jul 07, 2018 2:41 pm

Thanks a lot for you awesome work and tutorials!

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

Re: uasyncio

Post by pythoncoder » Sun Jul 08, 2018 9:39 am

Thank you. My enthusiasm for uasyncio stems from the fact that in 43 (gulp) years of developing firmware most of the nontrivial applications used cooperative multi-tasking. Also from experience of debugging applications using pre-emptive multi tasking. A total can of worms :(
Peter Hinch

cefn
Posts: 205
Joined: Tue Aug 09, 2016 10:58 am

Re: uasyncio

Post by cefn » Mon Jul 09, 2018 10:12 pm

"in 43 (gulp) years of developing firmware most of the nontrivial applications used cooperative multi-tasking"

It's great to have someone with your kind of experience wanting to give back to the community - a level of commitment which deserves real recognition, and passes on insights from so many years of learning-by-doing. Thanks for all your efforts!

Post Reply