QUERY · ISSUE
uasyncio emits no error message if a coro is called rather than awaited.
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
Unix build: uasyncio __await__ not called
Is this special method supported? The following code behaves differently under CPython and MicroPython.
import uasyncio as asyncio
class Foo():
def __iter__(self):
for n in range(5):
print('__iter__ called')
yield
def __await__(self):
for n in range(5):
print('__await__ called')
yield
async def bar():
foo = Foo()
print('waiting for foo')
await foo
print('done')
async def main(delay):
await asyncio.sleep(delay)
print("I've seen starships burn off the shoulder of Orion...")
print("Time to die...")
loop = asyncio.get_event_loop()
loop.create_task(bar())
loop.run_until_complete(main(5))
Under CPython the outcome is as expected: __iter__() is not called, __await__() is:
Python 3.5.2 (default, Dec 2 2016, 15:29:25)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rats6
waiting for foo
__await__ called
5
4
3
2
1
done
I've seen starships burn off the shoulder of Orion...
Time to die...
>>>
Under MicroPython the converse is true:
MicroPython v1.8.1-925-g46e59c5 on 2016-12-03; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import rats6
waiting for foo
__iter__ called
__iter__ called
__iter__ called
__iter__ called
__iter__ called
done
I've seen starships burn off the shoulder of Orion...
Time to die...
>>>