I am attempting to learn how ascyncio works, and have copied the example from section 7.3 the uasyncho approach of the tutorial (see below). I have successfully copied the uasyncio module and also the collections/deque module from the micropyton-lib (using upip) to the sd card on my pyboard.
I am using the latest standard firmware i.e. MicroPython v1.9.3 on 2017-11-01; PYBLITEv1.0 with STM32F411RE)
Now when I run the code below I get the following error,
Traceback (most recent call last):
File "main.py", line 39, in <module>
File "main.py", line 39, in <listcomp>
File "main.py", line 11, in __init__
File "uasyncio/core.py", line 224, in get_event_loop
File "uasyncio/__init__.py", line 21, in __init__
File "uasyncio/core.py", line 30, in __init__
AttributeError: 'module' object has no attribute 'deque'
The error seems to be to do with the following line
Code: Select all
loop = asyncio.get_event_loop()
Code: Select all
import pyb
import uasyncio as asyncio
from collections import * #my addition to example code
#copied from "7.3 the uasyncho approach"
class LED_async():
def __init__(self, led_no):
self.led = pyb.LED(led_no)
self.rate = 0
loop = asyncio.get_event_loop()
loop.create_task(self.run())
async def run(self):
while True:
if self.rate <= 0:
await asyncio.sleep_ms(200)
else:
self.led.toggle()
await asyncio.sleep_ms(int(500 / self.rate))
def flash(self, rate):
self.rate = rate
def on(self):
self.led.on()
self.rate = 0
def off(self):
self.led.off()
self.rate = 0
async def killer():
sw = pyb.Switch()
while not sw.value():
await asyncio.sleep_ms(100)
leds = [LED_async(n) for n in range(1, 4)]
for n, led in enumerate(leds):
led.flash(0.7 + n/4)
loop = asyncio.get_event_loop()## this line is problematic
loop.run_until_complete(killer())