code: def _chain_resolve_failure(new_future, reason, on_failure=None):
      try:
          if on_failure:
              try:
                  reason = on_failure(reason)
                  if isinstance(reason, Future):
                      _chain_resolve_future(new_future, reason)
                  elif isinstance(reason, BaseException):
                      new_future.set_exception(reason)
                  else:
                      new_future.set_result(reason)
              except BaseException as exception:
                  new_future.set_exception(exception)
          else:
              new_future.set_exception(reason)
      finally:
          del new_future, reason, on_failure
  
file_path: mpi4py/src/mpi4py/futures/aplus.py
imports: import functools
  import threading
  import weakref
  from ._base import Future
label_desc: Use image node_id 7 for calling a global function with example usage: _chain_resolve_failure(new_future, reason, on_failure) without return types