code: def test_finish_always_called():
      flag = [False]
  
      class MyCallback(Callback):
          def _finish(self, dsk, state, errored):
              flag[0] = True
              assert errored
  
      dsk = {"x": (lambda: 1 / 0,)}
  
      # `raise_on_exception=True`
      try:
          with MyCallback():
              get_sync(dsk, "x")
      except Exception as e:
          assert isinstance(e, ZeroDivisionError)
      assert flag[0]
  
      # `raise_on_exception=False`
      flag[0] = False
      try:
          with MyCallback():
              get_threaded(dsk, "x")
      except Exception as e:
          assert isinstance(e, ZeroDivisionError)
      assert flag[0]
  
      # KeyboardInterrupt
      def raise_keyboard():
          raise KeyboardInterrupt()
  
      dsk = {"x": (raise_keyboard,)}
      flag[0] = False
      try:
          with MyCallback():
              get_sync(dsk, "x")
      except BaseException as e:
          assert isinstance(e, KeyboardInterrupt)
      assert flag[0]
  
file_path: dask/dask/tests/test_callbacks.py
imports: from __future__ import annotations
  from dask.callbacks import Callback
  from dask.local import get_sync
  from dask.threaded import get
  from dask.utils_test import add
label_desc: Use image node_id 3 for calling a global function with example usage: test_finish_always_called() without return types