Open
Description
Consider this script:
try:
import uasyncio as asyncio
except ImportError:
import asyncio
evt = asyncio.Event()
async def foo():
try:
await evt.wait()
finally:
print('Finally')
async def main():
t = asyncio.create_task(foo())
await asyncio.sleep(1)
t. cancel()
# Can be fixed with .sleep(0) here
print('canned')
await asyncio.sleep(1)
asyncio.run(main())
On MP the outcome is:
MicroPython v1.19.1-617-g43dd3ea74 on 2022-11-08; linux [GCC 9.4.0] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import rats
canned
Finally
>>>
On CPython:
$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rats
Finally
canned
>>>
MP behaviour also confirmed on Pyboard.