asyncio.run on unix port

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

asyncio.run on unix port

Post by uraich » Sat Oct 17, 2020 9:01 am

When trying to use asyncio.run on the unix port I get the error
AttributeError: 'module' object has no attribute 'run'
When running the same thing on the esp32 everything works as expected. I have attached the very simple demo program on which I can check this. Any idea why this is the case?
Attachments
asyncio.png
asyncio.png (15.08 KiB) Viewed 2520 times

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

Re: asyncio.run on unix port

Post by pythoncoder » Sat Oct 17, 2020 1:03 pm

That script works here. Please check if you have uasyncio V3:

Code: Select all

import uasyncio
print(uasyncio.__version__)
should produce (3, 0, 0). If it produces an exception you have V2, in which case you need to get the latest sources and rebuild the Unix port.
Peter Hinch
Index to my micropython libraries.

uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

Re: asyncio.run on unix port

Post by uraich » Sat Oct 17, 2020 7:03 pm

Thanks Pete,
That's weird! I built the Unix version and the ESP32 from the same MicroPython sources. The ESP32 version works, the Unix version seems to use uasyncio V2.
Just to be sure I cloned MicroPython from github just now and rebuilt the Unix version. Do I have to give an option to make to get uasyncio V3?
Attachments
uasyncio.png
uasyncio.png (34.12 KiB) Viewed 2496 times

uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

Re: asyncio.run on unix port

Post by uraich » Sat Oct 17, 2020 7:29 pm

Hi Pete,
Your answer pointed me into the right direction: The standard version of unix micropython uses uasyncio V2 (I think this should be changed!). If I build the "dev" version, I get V3.

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

Now I'm foxed...

Post by pythoncoder » Sun Oct 18, 2020 1:46 pm

Now it's me who's baffled. I've just fetched the latest sources and rebuilt. My build script does make clean then make in the unix directory. Here is the outcome:

Code: Select all

MicroPython v1.13-107-g18518e26a-dirty on 2020-10-18; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import uasyncio
>>> uasyncio.__version__
(3, 0, 0)
>>> 
My unix build has uasyncio V3. So why do our results differ?

[EDITED]
Looking at my build, uasyncio is not being built as frozen bytecode: I think we both know the reason having studied the manifests and makefile.

What is happening is that the module is running as Python code. The task queue has C and Python implementations, so uasyncio can run without frozen code. I proved that it is running as Python code by renaming extmod/uasyncio.core.py and the import duly broke.

The things that puzzle me are:
  • How is my build finding that directory.
  • Why is yours not doing so.
My sys.path is

Code: Select all

['', '/home/adminpete/.micropython/lib', '/usr/lib/micropython']
Peter Hinch
Index to my micropython libraries.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: asyncio.run on unix port

Post by jimmo » Tue Oct 20, 2020 6:18 am

My guess is that uraich has previously installed v2 from micropython-lib and it's in ~/.micropython/lib and being used preferentially over the frozen v3 code.

uraich
Posts: 56
Joined: Tue Mar 26, 2019 12:24 pm

Re: asyncio.run on unix port

Post by uraich » Wed Oct 21, 2020 2:07 pm

Hi jimmo
You are perfectly right. In fact uasyncio is not included in the standard unix micropython at all and my micropython found it in $HOME/.micropython, which was from the micropython-lib. The dev variant includes uasyncio and it include V3 of it.

Post Reply