uasyncio - determining if a function is a coroutine

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.
tannewt
Posts: 51
Joined: Thu Aug 25, 2016 2:43 am

Re: uasyncio - determining if a function is a coroutine

Post by tannewt » Tue Jul 20, 2021 1:31 am

kevinkk525 wrote:
Mon Jul 19, 2021 7:30 am
lol ok.. interesting. Why didn't they just use the "official" uasyncio module? .. (sorry I know you're not the right person for this question)
I think it was a bit of a timing thing. IIRC WarriorOfWire did the work to turn the keywords on before we had done the big merge from 1.9.4ish up to 1.15 (and we've merged 1.16 in now too.) I'm happy to review changes to turn on uasyncio but I may push to make it CPython compatible if it isn't (I haven't looked.) That's why we have a generator/coroutine distinction in our implementation. We didn't want folks to write non-cpython compatible async code by mixing coroutine and generator use.

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

Re: uasyncio - determining if a function is a coroutine

Post by kevinkk525 » Tue Jul 20, 2021 5:00 am

ok thanks for the info. The current uasyncio implementation is CPython compatible almost everywhere because this time it was a basic requirement to be CPython compatible. But it does not distinguish between a coroutine and a generator.
But from the top of my head I can't think of how someone would accidentally mix generator and coroutine usage. Maybe my imagination is not good enough :D
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: uasyncio - determining if a function is a coroutine

Post by pythoncoder » Tue Jul 20, 2021 5:09 am

uasyncio V3 supports asyncio syntax. Writing portable code is very easy. uasyncio does have some microcontroller oriented extensions such as sleep_ms(). By contrast tasko is just weird with syntax like

Code: Select all

tasko.schedule(hz=100, coroutine_function=rotary.loop)
I've worked with (and written) schedulers for many years. I've never seen it done this way and I think I know why...

I strongly recommend uasyncio V3: it is excellent.
Peter Hinch
Index to my micropython libraries.

Post Reply