Title: Theory / Unimportant / CS / Programming / Python / Async / Task
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://docs.python.org/3.10/library/asyncio-task.html

Instruction: taskOrFuture.cancel(msg=None)
Effect: Request taskOrFuture to be cancelled.
This arranges for a CancelledError exception to be thrown into the wrapped coroutine on the next cycle of the event loop.
Language: python
Variables: task = async.Task(coro, *, loop=loop, name=name)

Instruction: taskOrFuture.cancelled()
Language: python
Returns: Whether the task was cancelled
Variables: taskOrFuture = async.Task(coro, *, loop=loop, name=name)

Instruction: taskOrFuture.result()
Language: python
Returns: result of taskOrFuture, if it is available (coroutine ended, set_result was called)
Variables: task = async.Task(coro, *, loop=loop, name=name)
Exception: re-raise the exception raised by the coroutine, if any
CancelledError if the task was cancelled
InvalidStateError if result isn't yet available

Instruction: taskOrFuture.exception()
Language: python
Returns: the exception raised by the task, put by set_exception, or None
Variables: task = async.Task(coro, *, loop=loop, name=name)
Exception: CancelledError if task is cancelled
InvalidStateError if the task is not yet done

Instruction: taskOrFuture.add_done_callback(
  callback,
  *,
  context=None
)
Effect: ensure that callback is called when the add_done_callback is done (see Future.add_done_callback())
Language: python
Variables: task = async.Task(
  coro,
  *,
  loop=loop,
  name=name
)
Assuming: low-level callback-based code

Instruction: task.remove_done_callback(callback)
Effect: remove callback from the task
Language: python
Variables: task = async.Task(coro, *, loop=loop, name=name)
Assuming: low-level callback-based code

Instruction: task.get_stack(
  *,
  limit=None
)
Language: python
Returns: the stack where the task is suspended, or exception was raised. empty stack if task is done
Variables: task = async.Task(
  coro,
  *,
  loop=loop,
  name=name
)

Instruction: task.print_stack(
  *,
  limit=None,
  file=None
)
Effect: print result of get_stack(*, limit=limit) in file or stderr
Language: python
Variables: task = async.Task(
  coro,
  *,
  loop=loop,
  name=name
)

Instruction: task.get_coro()
Language: python
Returns: The coroutine wrapped by the task
Variables: task = async.Task(coro, *, loop=loop, name=name)

Instruction: task.get_name()
Language: python
Returns: the name of the task; explicitly assigned or generated during instantiation
Variables: task = async.Task(coro, *, loop=loop, name=name)

Instruction: task.set_name(value)
Effect: set the name of the task to value
Language: python
Variables: task = async.Task(coro, *, loop=loop, name=name)