← index #3241Issue #3005
Off-topic · high · value 2.906
QUERY · ISSUE

uasyncio emits no error message if a coro is called rather than awaited.

openby peterhinchopened 2017-07-25updated 2026-03-26
extmod

The following

import uasyncio as asyncio

async def bar():
    await asyncio.sleep(1)
    print('In bar')

async def foo():
    print('Launching bar')
    await bar()
    print('Getting it wrong')
    bar()  # bad

loop = asyncio.get_event_loop()
loop.run_until_complete(foo())

produces this output

>>> import rats37
Launching bar
In bar
Getting it wrong
>>> 

CPython 3.5.2 issues the following error message:

>>> import rats37
Launching bar
In bar
Getting it wrong
/home/adminpete/rats37.py:11: RuntimeWarning: coroutine 'bar' was never awaited
  bar()
>>> 

It would be useful if a message were emitted in response to this error.

CANDIDATE · ISSUE

uasyncio stream reader/writer: unexpected behaviour with UART

closedby peterhinchopened 2017-04-06updated 2017-04-07

Testing done on Pyboard V1.1. The sender coroutine iterates every 2 seconds but no output appears on pin X1:

import uasyncio as asyncio
from pyb import UART
uart = UART(4, 9600)

async def sender():
    swriter = asyncio.StreamWriter(uart, {})
    while True:
        swriter.awrite('Hello uart\n')
        await asyncio.sleep(2)
        print('wrote')

loop = asyncio.get_event_loop()
loop.create_task(sender())
loop.run_forever()

The next script produces output on X1 as expected until a loopback is applied (link X1 and X2). At this point the UART sends data continuously. The data is read correctly, but the call to

await asyncio.sleep(2) no longer behaves as expected.

import uasyncio as asyncio
from pyb import UART
uart = UART(4, 9600)

async def sender():
    while True:
        uart.write('Hello uart\n')
        await asyncio.sleep(2)
        print('Wrote')

async def receiver():
    sreader = asyncio.StreamReader(uart)
    while True:
        res = await sreader.readline()
        print('Recieved', res)

loop = asyncio.get_event_loop()
loop.create_task(sender())
loop.create_task(receiver())
loop.run_forever()

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied