← index #9737PR #13000
Related · high · value 3.261
QUERY · ISSUE

asyncio implement cpython all_tasks

openby ThinkTransitopened 2022-10-25updated 2022-10-25
enhancement

It would be very useful to have the ability to get a list of all tasks similar to the cpython implementation.

all_tasks

Currently to track all running tasks, tasks must be stored in a global list variable which is not ideal and error prone.

  • Would you be willing to sponsor this work? Yes
CANDIDATE · PULL REQUEST

extmod/asyncio: Add `Task` methods from CPython

openby imnotjamesopened 2023-11-17updated 2024-03-07
extmod

This updates the way that Task is defined in the C module for asyncio which implements tasks & task queues. The goal is to bring asyncio in MicroPython 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)

~Adds a hash unary operation so Tasks can be added to sets like in CPython.~

~Also adds set_result and set_exception for consistency but neither of these do anything - they raise a RuntimeError because they aren't supported on Tasks. :shrug:~

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied