Asyncio in uPython 1.14 has not "run"???

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 3:17 am

Hi,
I just installed MicroPython 1.14 and trying to understand non-blocking tasks I ran this example code from MicroPython 1.14 documentation:

Code: Select all

import uasyncio

async def blink(led, period_ms):
    while True:
        led.on()
        await uasyncio.sleep_ms(5)
        led.off()
        await uasyncio.sleep_ms(period_ms)

async def main(led1, led2):
    uasyncio.create_task(blink(led1, 700))
    uasyncio.create_task(blink(led2, 400))
    await uasyncio.sleep_ms(10_000)
    
from machine import Pin
uasyncio.run(main(Pin(1), Pin(2)))
but got this error:

Code: Select all

AttributeError: 'module' object has no attribute 'run'
Please, can anyone explain me what's wrong?
Thanks.

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

Re: Asyncio in uPython 1.14 has not "run"???

Post by kevinkk525 » Sun Feb 07, 2021 6:00 am

Strange. What does this return?: "uasyncio.__version__"
Did you have an older micropython on that microcontroller before and possible the files for the old uasyncio? Because this new version of uasyncio was introduced in micropython 1.13.
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: Asyncio in uPython 1.14 has not "run"???

Post by pythoncoder » Sun Feb 07, 2021 7:51 am

The code runs here on a Pyboard (just changing the pin ID's). I agree with @kevinkk525: I suspect you have old firmware. You need V1.13 or the latest V1.14. What do you see when the board boots up?
Peter Hinch
Index to my micropython libraries.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 12:50 pm

pythoncoder wrote:
Sun Feb 07, 2021 7:51 am
The code runs here on a Pyboard (just changing the pin ID's). I agree with @kevinkk525: I suspect you have old firmware. You need V1.13 or the latest V1.14. What do you see when the board boots up?

Code: Select all

MicroPython v1.14 on 2021-02-02; ESP module (1M) with ESP8266.
It seems the last release.
However I had a 1.13 but it issued the same problem. And the uasyncio gets imported without any problem.
"run" seems not present in its methods:

Code: Select all

>>> import uasyncio
>>> dir(uasyncio)
['__class__', '__name__', '__path__', 'log', 'select', 'sleep', 'sleep_ms', 'time', 'ucollections', 'uerrno', 'utimeq', 'DEBUG', 'uasyncio', '_socket', 'core', 'set_debug', 'PollEventLoop', 'EventLoop', 'StreamReader', 'IORead', 'IOReadDone', 'StreamWriter', 'IOWrite', 'IOWriteDone', 'open_connection', 'start_server', 'type_gen', 'CancelledError', 'TimeoutError', 'SysCall1', 'SleepMs', 'StopLoop', 'SysCall', 'get_event_loop', 'cancel', 'TimeoutObj', 'wait_for_ms', 'wait_for', 'coroutine', 'ensure_future', 'Task']
>>> 
Indeed no "run" method here!

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 12:52 pm

kevinkk525 wrote:
Sun Feb 07, 2021 6:00 am
Strange. What does this return?: "uasyncio.__version__"
Did you have an older micropython on that microcontroller before and possible the files for the old uasyncio? Because this new version of uasyncio was introduced in micropython 1.13.

Code: Select all

>>> uasyncio.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'
I flashed the 1.14 and just copied the example from MicroPython 1.14 reference.

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

Re: Asyncio in uPython 1.14 has not "run"???

Post by kevinkk525 » Sun Feb 07, 2021 1:46 pm

Since you don't have __version__, you have an old uasyncio version from before micropython 1.13..
which board are you using? What did you have on your board previously? Did you erase the flash before flashing the 1.14 firmware?

If you didn't have any files before, we might have to check the 1.14 release firmware.
I only downloaded the daily build for esp32 and it has a correct uasyncio.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 6:39 pm

kevinkk525 wrote:
Sun Feb 07, 2021 1:46 pm
Since you don't have __version__, you have an old uasyncio version from before micropython 1.13..
which board are you using? What did you have on your board previously? Did you erase the flash before flashing the 1.14 firmware?

If you didn't have any files before, we might have to check the 1.14 release firmware.
I only downloaded the daily build for esp32 and it has a correct uasyncio.
I'm using an ESP8266 MCU (the most common one as I can see). I'm using these boards since more than an year and ALWAYS erase the flash memory before flashing a new firmware.
In this board I had a stable 1.13 for months and all was ok (but uasyncio which I never used before).
I always download the firmware from "https://micropython.org/download/all/" and this time I downloaded this one: "https://micropython.org/resources/firmw ... -v1.14.bin".
This seems the last stable release, isn't it?

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

Re: Asyncio in uPython 1.14 has not "run"???

Post by kevinkk525 » Sun Feb 07, 2021 7:27 pm

that's right. Looks like you're doing it correctly.
You could try the daily firmware until we can find out whats happening (assuming the daily firmware has uasyncio v3 which I assume it does).
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 7:48 pm

kevinkk525 wrote:
Sun Feb 07, 2021 7:27 pm
that's right. Looks like you're doing it correctly.
You could try the daily firmware until we can find out whats happening (assuming the daily firmware has uasyncio v3 which I assume it does).
I'll give it a try and let you know.

enzo
Posts: 40
Joined: Thu Jun 11, 2020 1:03 am

Re: Asyncio in uPython 1.14 has not "run"???

Post by enzo » Sun Feb 07, 2021 7:57 pm

enzo wrote:
Sun Feb 07, 2021 7:48 pm
kevinkk525 wrote:
Sun Feb 07, 2021 7:27 pm
that's right. Looks like you're doing it correctly.
You could try the daily firmware until we can find out whats happening (assuming the daily firmware has uasyncio v3 which I assume it does).
I'll give it a try and let you know.
Same problem with last unstable:

Code: Select all

MicroPython v1.14-9-g9dedcf122 on 2021-02-07; ESP module (1M) with ESP8266
Type "help()" for more information.
>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 20, in <module>
AttributeError: 'module' object has no attribute 'run'

Code: Select all

>>> import uasyncio
>>> dir(uasyncio)
['__class__', '__name__', '__path__', 'log', 'select', 'sleep', 'sleep_ms', 'time', 'ucollections', 'uerrno', 'utimeq', 'DEBUG', 'uasyncio', '_socket', 'core', 'set_debug', 'PollEventLoop', 'EventLoop', 'StreamReader', 'IORead', 'IOReadDone', 'StreamWriter', 'IOWrite', 'IOWriteDone', 'open_connection', 'start_server', 'type_gen', 'CancelledError', 'TimeoutError', 'SysCall1', 'SleepMs', 'StopLoop', 'SysCall', 'get_event_loop', 'cancel', 'TimeoutObj', 'wait_for_ms', 'wait_for', 'coroutine', 'ensure_future', 'Task']
>>> 
I see there's a "uasyncio" method in "uasyncio" module so I tried:

Code: Select all

>>> uasyncio.uasyncio.run()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'
>>> 
but no success.

Post Reply