QUERY · ISSUE
uasyncio StreamReader fails if UART times out.
bug
I'm unsure if this qualifies as a bug as there is an obvious workround.
The issue arose in this report. If the UART receiver times out the device returns None which causes uasyncio to fail here.
CANDIDATE · ISSUE
uasyncio StreamReader/StreamWriter can fail if a coro blocks on an awaitable
The following runs on a Pyboard with a link between X1 and X2. If the Bar class is changed such that the sleep time is zero, the UART I/O does not take place.
# Link X1 and X2 to test.
import uasyncio as asyncio
from pyb import UART
uart = UART(4, 9600)
async def sender():
swriter = asyncio.StreamWriter(uart, {})
while True:
await swriter.awrite('Hello uart\n')
await asyncio.sleep(2)
async def receiver():
sreader = asyncio.StreamReader(uart)
while True:
res = await sreader.readline()
print('Recieved', res)
class Bar():
def __await__(self):
while True:
yield from asyncio.sleep_ms(5) # Change this to 0 and the app fails
__iter__ = __await__
bar = Bar()
async def foo():
print('Starting foo. Should never finish.')
await bar
print('foo finished.')
loop = asyncio.get_event_loop()
loop.create_task(foo())
loop.create_task(sender())
loop.create_task(receiver())
loop.run_forever()