Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Task methods to make _asyncio more similar to cpython #8576

Closed

Conversation

imnotjames
Copy link

@imnotjames imnotjames commented Nov 10, 2023

This updates the way that Task is handled in the C module for asyncio which implements tasks & task queues. The goal is to bring asyncio in CircuitPython slightly closer to CPython.

This adds the following methods to Task:

  • get_coro() - how CPython exposes the coroutine backing the task (CPython Docs)
  • result() - a helper method from CPython for returning the successful response (CPython Docs)
  • exception() - a helper method from CPython for returning the raised values (CPython Docs)
  • cancelled() - helper for true / false if the task has been cancelled (CPython Docs)
  • add_done_callback() - adds a callback to the task for completion or if already complete executes it (CPython docs)
  • remove_done_callback() - removes a specific "done" callback from the task (CPython docs)

Moves CancelledError & creates InvalidStateError in the extmod

Adds a hash unary operation so Tasks can be added to sets.

To Do:

  • Support add_done_callback / remove_done_callback
  • Add tests for new features

@imnotjames
Copy link
Author

Tests are going to fail until adafruit_asyncio uses the CancelledError from _asyncio. Opened adafruit/Adafruit_CircuitPython_asyncio#55 for this unless there's a different way this should be handled.

@imnotjames imnotjames force-pushed the feat/more-asyncio-task-methods branch 3 times, most recently from 8a8e1a7 to 37055e9 Compare November 11, 2023 02:08
@dhalbert
Copy link
Collaborator

You will need to advance the submodule commit for the asyncio library.

@imnotjames
Copy link
Author

I'm trying my luck upstream first - micropython#13000 - I'll close this PR out for the time being. Hopefully can just port this back here!

@imnotjames imnotjames closed this Nov 19, 2023
@dhalbert
Copy link
Collaborator

We usually don't merge from MicroPython upstream until they release a major version, so if it looks like this is approximately the way it's going to go, fine to leave this open. Once you update the asyncio submodule here, I think the tests will run?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants