code: def _compose_complete(context, old_future):
      new_future, resulthook, excepthook = context.pop()
      try:
          if old_future.cancelled():
              new_future.cancel()
          elif old_future.exception() is not None:
              reason = old_future.exception()
              if excepthook:
                  reason = excepthook(reason)
              if isinstance(reason, BaseException):
                  new_future.set_exception(reason)
              else:
                  new_future.set_result(reason)
          else:
              result = old_future.result()
              if resulthook:
                  result = resulthook(result)
              new_future.set_result(result)
      except BaseException as exception:
          new_future.set_exception(exception)
      finally:
          new_future = None
          old_future = None
          result = resulthook = None
          reason = excepthook = None
  
file_path: mpi4py/src/mpi4py/futures/util.py
imports: import collections
  import functools
  import threading
  from .None import _base
label_desc: Use image node_id 4 for calling a global function with example usage: _compose_complete(context, old_future) without return types