Skip to content

asyncio.wait_for broken in micropython #2415

@rasjidw

Description

@rasjidw

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

The simplest code I can recreate the problem with is as follows:

import asyncio

async def delayed_value():
    await asyncio.sleep(2)
    return 'Delayed Value'

async def simple_test(event):
    "Call this from a button"
    try:
        result = await asyncio.wait_for(delayed_value(), timeout=5)
        print(f'*** Got result: {result}')
    except asyncio.TimeoutError:
        print('*** Operation timed out ***')

Linking a button to 'simple_test' and clicking on the button works in CPython build, but fails in the MicroPython build of PyScript with:

Task exception wasn't retrieved
future: coro= <class 'TopLevelCoro'>
Traceback (most recent call last):
File "asyncio/core.py", line 1, in _run_iter
AttributeError: type object 'TopLevelCoro' has no attribute 'throw'

What browsers are you seeing the problem on? (if applicable)

Firefox, Chrome

Console info

Additional Context

I've checked that the code works fine in Micropython on Linux (tested with MicroPython v1.26.0 on 2025-08-13; linux [GCC 13.3.0] version), so it seems to be something specific either to PyScript or the specific build of Micropython being used with the current release (2025.11.2) - although I was hitting the issue with earlier versions of Micropython on PyScript as well, but had not been able to isolate the cause and create a simple test case at that point.

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