8000 uasyncio: Behaviour differs from CPython. · Issue #9993 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
uasyncio: Behaviour differs from CPython. #9993
Open
@peterhinch

Description

@peterhinch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0