micropython / micropython/micropython-lib

usayncio: TypeError: exceptions must derive from BaseException

Open
#268 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Description

I have written some code that uses the asyncio module. The entrypoint point to my code looks like this:

try:
    control.main()
except KeyboardInterrupt:
    pass
except Exception as exc:
    sys.print_exception(exc)
    print('* resetting in 10 seconds')
    time.sleep(10)
    machine.reset()

And control.main looks like:

def main():
    [...]

    try:
        loop.run_forever()
        loop.close()
    finally:
        for task in tasklist:
            task.close()

I just upgraded to the version in micropython-lib as of 9e21d6e, and now when I interrupt my code with ^C I see the following error:

Traceback (most recent call last):
  File "snakecharmer/main.py", line 10, in <module>
  File "snakecharmer/control.py", line 52, in main
  File "uasyncio/__init__.py", line 246, in start_server
TypeError: exceptions must derive from BaseException

That seems to correspond to the following line in uasyncio/__init__.py:

yield IORead(s)

What's going on here?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with uasyncio/init.py at the reported line 246, then trace how control.py:main and snakecharmer/main.py handle Ctrl-C. Compare the behavior before and after micropython-lib revision 9e21d6e. Done means explaining why the interrupt reaches this error and identifying the affected change or correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.