code: def one_rank_only(
      rank: int = 0, with_barrier: bool = False
  ) -> Callable:
      """Decorator to filter handlers wrt a rank number
  
      Args:
          rank: rank number of the handler (default: 0).
          with_barrier: synchronisation with a barrier (default: False).
  
      Examples:
          .. code-block:: python
  
              engine = ...
  
              @engine.on(...)
              @one_rank_only() # means @one_rank_only(rank=0)
              def some_handler(_):
                  ...
  
              @engine.on(...)
              @one_rank_only(rank=1)
              def some_handler(_):
                  ...
      """
  
      def _one_rank_only(func: Callable) -> Callable:
          @wraps(func)
          def wrapper(*args: Any, **kwargs: Any) -> Optional[Any]:
              ret = None
              if get_rank() == rank:
                  ret = func(*args, **kwargs)
              if with_barrier:
                  barrier()
              return ret
  
          return wrapper
  
      return _one_rank_only
  
imports: import socket
  from contextlib import contextmanager
  from functools import wraps
  from typing import Any, Callable, List, Mapping, Optional, Tuple, Union
  import torch
  from ignite.distributed.comp_models import _SerialModel, has_hvd_support, has_native_dist_support, has_xla_support, registered_computation_models
  from ignite.utils import setup_logger
label_desc: Use image node_id 25 for calling a global function with example usage: one_rank_only(rank, with_barrier) and returns: _one_rank_only, wrapper, ret