adafruit / Adafruit_CircuitPython_asyncio

CIrcuitPython subset of CPython asyncio library
MIT License
28 stars 16 forks source link

core.py calls nonexistent function sys.print_exception #10

Closed rimwolf-redux closed 2 years ago

rimwolf-redux commented 2 years ago

Various errors using asyncio result in a traceback leading to line core.py:283, like this from the included code.py, which contains a task that tries to call a string:

    code.py output:
    Task exception wasn't retrieved
    future: <Task object at 0x200275b0> coro= <coroutine object 'main' at 0x20004000>
    Traceback (most recent call last):
      File "code.py", line 11, in <module>
      File "asyncio/core.py", line 235, in run
      File "asyncio/core.py", line 230, in run_until_complete
      File "asyncio/core.py", line 287, in call_exception_handler
      File "asyncio/core.py", line 283, in default_exception_handler
    AttributeError: 'module' object has no attribute 'print_exception'

If I change the sys.print_exception call to:

traceback.print_exception(None, context["exception"], None)

then the console output is:

code.py output: Task exception wasn't retrieved future: <Task object at 0x200275a0> coro= <coroutine object 'main' at 0x20004000> TypeError: 'str' object is not callable

The example code.py:

import os, asyncio

async def bad():
    os.sep()  # os.sep NOT CALLABLE
    print('after')

async def main():
    bad_task = asyncio.create_task(bad())
    await asyncio.gather(bad_task)

asyncio.run(main())

Running CP 7.1.0-beta.1 on a PyBadge, asyncio source code 0.50

dhalbert commented 2 years ago

I fixed that one place but not another. Thanks! Will fix soon.

dhalbert commented 2 years ago

This was fixed in 0.5.1.