code: def singleton_client(cls):
      """
      A singleton decorator helps us to make sure there is only one instance
      """
      instances = {}
  
      def get_instance(*args, **kwargs):
          if cls not in instances:
              instances[cls] = (cls(*args, **kwargs), time.time())
          else:
              instance, last_checked_time = instances[cls]
              current_time = time.time()
              if (
                  current_time - last_checked_time
                  > Constants.ENSURE_CONNECTION_PERIOD
              ):
                  instance.ensure_connect()
                  instances[cls] = (instance, current_time)
          return instances[cls][0]
  
      # For singleton-decorator, it can't direct access to the class object
      # without decorator. So you cannot call methods using a class name in unit tests.
      # It would not work because You Class actually contains a wrapper function but not
      # your class object. This is a workaround solution for this issue. It uses a
      # separate wrapper object for each decorated class and holds a class within
      # __wrapped__ attribute so you can access the decorated class directly in your
      # unit tests.
      # Please refer to https://stackoverflow.com/questions/70958126
      # /how-to-mock-a-method-inside-a-singleton-decorated-class-in-python
      get_instance.__wrapped__ = cls
  
      return get_instance
  
file_path: ray/python/ray/autoscaler/_private/vsphere/utils.py
imports: import ipaddress
  import time
  from datetime import datetime
  from enum import Enum
label_desc: Use image node_id 2 for calling a global function with example usage: singleton_client(cls) and returns: get_instance, instances