code: def test_mpfuture_done_callback():
      receiver, sender = mp.Pipe(duplex=False)
      events = [mp.Event() for _ in range(6)]
  
      def _future_creator():
          future1, future2, future3 = (
              hivemind.MPFuture(),
              hivemind.MPFuture(),
              hivemind.MPFuture(),
          )
  
          def _check_result_and_set(future):
              assert future.done()
              assert future.result() == 123
              events[0].set()
  
          future1.add_done_callback(_check_result_and_set)
          future1.add_done_callback(lambda future: events[1].set())
          future2.add_done_callback(lambda future: events[2].set())
          future3.add_done_callback(lambda future: events[3].set())
  
          sender.send((future1, future2))
          future2.cancel()  # trigger future2 callback from the same process
  
          events[0].wait()
          future1.add_done_callback(
              lambda future: events[4].set()
          )  # schedule callback after future1 is already finished
          events[5].wait()
  
      p = mp.Process(target=_future_creator)
      p.start()
  
      future1, future2 = receiver.recv()
      future1.set_result(123)
  
      with pytest.raises(RuntimeError):
          future1.add_done_callback(lambda future: (1, 2, 3))
  
      assert future1.done() and not future1.cancelled()
      assert future2.done() and future2.cancelled()
      for i in 0, 1, 4:
          events[i].wait(1)
      assert (
          events[0].is_set()
          and events[1].is_set()
          and events[2].is_set()
          and events[4].is_set()
      )
      assert not events[3].is_set()
  
      events[5].set()
      p.join()
  
imports: import asyncio
  import concurrent.futures
  import multiprocessing
  import random
  import time
  from concurrent.futures import ThreadPoolExecutor
  import numpy
  import pytest
  import torch
  import hivemind
  from hivemind.compression import deserialize_torch_tensor, serialize_torch_tensor
  from hivemind.proto.runtime_pb2 import CompressionType
  from hivemind.utils import BatchTensorDescriptor, DHTExpiration, HeapEntry, MSGPackSerializer, ValueWithExpiration
  from hivemind.utils.asyncio import achain, aenumerate, aiter_with_timeout, amap_in_executor, anext, as_aiter, asingle, attach_event_on_finished, azip, cancel_and_wait, enter_asynchronously
  from hivemind.utils.mpfuture import InvalidStateError
  from hivemind.utils.performance_ema import PerformanceEMA
label_desc: Use image node_id 6 for calling a global function with example usage: test_mpfuture_done_callback() without return types