Page 1 of 1
asyncio.run on unix port
Posted: Sat Oct 17, 2020 9:01 am
by uraich
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?
Re: asyncio.run on unix port
Posted: Sat Oct 17, 2020 1:03 pm
by pythoncoder
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.
Re: asyncio.run on unix port
Posted: Sat Oct 17, 2020 7:03 pm
by uraich
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?
Re: asyncio.run on unix port
Posted: Sat Oct 17, 2020 7:29 pm
by uraich
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.
Now I'm foxed...
Posted: Sun Oct 18, 2020 1:46 pm
by pythoncoder
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']
Re: asyncio.run on unix port
Posted: Tue Oct 20, 2020 6:18 am
by jimmo
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.
Re: asyncio.run on unix port
Posted: Wed Oct 21, 2020 2:07 pm
by uraich
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.