code: def _chain_check_cycle(new_future, future):
      if new_future is future:
          raise RuntimeError(
              f"chain cycle detected: "
              f"Future {future} chained with itself"
          )
      with _chain_log_lock:
          registry = _chain_log_registry
          try:
              log = registry[new_future]
          except KeyError:
              log = weakref.WeakSet()
              registry[new_future] = log
          if future in log:
              raise RuntimeError(
                  f"chain cycle detected: "
                  f"Future {future} already in chain"
              )
          log.add(future)
  
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 4 for calling a global function with example usage: _chain_check_cycle(new_future, future) without return types