uasyncio for unix port

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
klapaucius
Posts: 1
Joined: Thu Jun 04, 2020 12:28 am

uasyncio for unix port

Post by klapaucius » Thu Jun 04, 2020 12:39 am

Apologies if this is answered elsewhere - couldn't find anything.

I'd like to test programs to be run on MCUs by first running them on the UNIX port. This sometimes breaks down, e.g. in the case of uasyncio:

It's present on the esp32 platform, but not on unix (and neither is the asyncio library).

so 1. Is there a decent way to use asyncio on the unix micropython port right now ?
2. if not, would it be good to add it (or asyncio) ? If so, is there a tutorial on how to port packages that I can follow and contribute (not promising, but having a tutorial makes it more likely I can do it)

3) Am I holding it wrong (e.g., should I test against regular python on unix/mac instead) ?

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

Re: uasyncio for unix port

Post by pythoncoder » Thu Jun 04, 2020 5:19 am

It is possible to install uasyncio on Unix using upip. However that will install uasyncio V2, whereas firmware daily builds have uasyncio V3 pre-installed. V3 is at an advanced stage of development. I believe that Unix support is intended but not yet deployed.

You will find a lot of information on uasyncio here including a V3 tutorial and a porting guide,

In summary many applications can be tested under V2 and will run under V3 but certain features (e.g. task cancellation) have changed for compatibility with CPython asyncio.

There is no realistic prospect of running the actual asyncio library on a microcontroller. Your other option is of course to test under CPython 3.8+ and asyncio but as uasyncio V3 is a subset there is a good deal of scope for error. My approach is to develop on a Pyboard.
Peter Hinch

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

Re: uasyncio for unix port

Post by kevinkk525 » Thu Jun 04, 2020 6:51 am

you can just copy the extmod/uasyncio directory into the module directory of the unix port. It worked last time I checked.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: uasyncio for unix port

Post by pythoncoder » Fri Jun 05, 2020 10:19 am

Thanks for that. On a very quick test that does seem to work, with no need to recompile.
Peter Hinch

garya@arcimoto.com
Posts: 7
Joined: Mon Oct 26, 2020 6:26 pm

Re: uasyncio for unix port

Post by garya@arcimoto.com » Thu Dec 17, 2020 8:14 pm

where is this "unix/modules" location you are referring to?

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

Re: uasyncio for unix port

Post by kevinkk525 » Thu Dec 17, 2020 9:55 pm

~/.micropython/lib
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

garya@arcimoto.com
Posts: 7
Joined: Mon Oct 26, 2020 6:26 pm

Re: uasyncio for unix port

Post by garya@arcimoto.com » Thu Dec 17, 2020 10:44 pm

Hi,
Thanks!
It is now there but I don't know how - was it from "import upip", import upip, upip.install('micropython-uasyncio')?

Now how do I get uasyncio to be in the build? I want to add it to STM32 build and any subsequent builds of micropython.

Thanks very much!

garya@arcimoto.com
Posts: 7
Joined: Mon Oct 26, 2020 6:26 pm

Re: uasyncio for unix port

Post by garya@arcimoto.com » Fri Dec 18, 2020 12:15 am

Hi,

Where is " into the module directory of the unix port?"
Will that give me a clue as to where I should put the uasyncio code to be included in a build for a STM32 device?

Thanks much!

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

Re: uasyncio for unix port

Post by kevinkk525 » Fri Dec 18, 2020 8:23 am

This has nothing to do with the STM32 build. This thread is only about the unix port. You can check about the STM build in a different thread (or start a new one if you can't find one). It's probably handled by board definitions.

For the unix port (sadly) you still have to use the dev build to have uasyncio included automatically. You have to use "make VARIANT=dev" in ~/micropython/ports/unix and then use ./micropython-dev
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply