class_docstr: Base class for using the callback mechanism
  
  Create a callback with functions of the following signatures:
  
  >>> def start(dsk):
  ...     pass
  >>> def start_state(dsk, state):
  ...     pass
  >>> def pretask(key, dsk, state):
  ...     pass
  >>> def posttask(key, result, dsk, state, worker_id):
  ...     pass
  >>> def finish(dsk, state, failed):
  ...     pass
  
  You may then construct a callback object with any number of them
  
  >>> cb = Callback(pretask=pretask, finish=finish)
  
  And use it either as a context manager over a compute/get call
  
  >>> with cb:            # doctest: +SKIP
  ...     x.compute()
  
  Or globally with the ``register`` method
  
  >>> cb.register()
  >>> cb.unregister()
  
  Alternatively subclass the ``Callback`` class with your own methods.
  
  >>> class PrintKeys(Callback):
  ...     def _pretask(self, key, dask, state):
  ...         print("Computing: {0}!".format(repr(key)))
  
  >>> with PrintKeys():   # doctest: +SKIP
  ...     x.compute()
class_docstr_tok: ["Base","class","for","using","the","callback","mechanism","Create","a","callback","with","functions","of","the","following","signatures",":",">",">",">","def","start","(","dsk",")",":","...","pass",">",">",">","def","start_state","(","dsk",",","state",")",":","...","pass",">",">",">","def","pretask","(","key",",","dsk",",","state",")",":","...","pass",">",">",">","def","posttask","(","key",",","result",",","dsk",",","state",",","worker_id",")",":","...","pass",">",">",">","def","finish","(","dsk",",","state",",","failed",")",":","...","pass","You","may","then","construct","a","callback","object","with","any","number","of","them",">",">",">","cb","=","Callback","(","pretask=pretask",",","finish=finish",")","And","use","it","either","as","a","context","manager","over","a","compute\/get","call",">",">",">","with","cb",":","#","doctest",":","+SKIP","...","x.compute","(",")","Or","globally","with","the","``","register","``","method",">",">",">","cb.register","(",")",">",">",">","cb.unregister","(",")","Alternatively","subclass","the","``","Callback","``","class","with","your","own","methods",".",">",">",">","class","PrintKeys","(","Callback",")",":","...","def","_pretask","(","self",",","key",",","dask",",","state",")",":","...","print","(","``","Computing",":","{","0","}","!","``",".format","(","repr","(","key",")",")",")",">",">",">","with","PrintKeys","(",")",":","#","doctest",":","+SKIP","...","x.compute","(",")"]
code: def __init__(
      self,
      start=None,
      start_state=None,
      pretask=None,
      posttask=None,
      finish=None,
  ):
      if start:
          self._start = start
      if start_state:
          self._start_state = start_state
      if pretask:
          self._pretask = pretask
      if posttask:
          self._posttask = posttask
      if finish:
          self._finish = finish
  
file_path: dask/dask/callbacks.py
imports: from __future__ import annotations
  from collections.abc import Callable
  from contextlib import contextmanager
  from typing import ClassVar
label_desc: Use image node_id 1 to create a new Callback object  with example: obj = Callback(start, start_state, pretask, posttask, finish)