code: def wait_services_ready(
      selectors: List,
      min_counts: List[int],
      count_fun: Callable,
      timeout=None,
  ):
      readies = [0] * len(selectors)
      start_time = time.time()
      while True:
          all_satisfy = True
          for idx, selector in enumerate(selectors):
              if readies[idx] < min_counts[idx]:
                  all_satisfy = False
                  readies[idx] = count_fun(selector)
                  break
          if all_satisfy:
              break
          if timeout and timeout + start_time < time.time():
              raise TimeoutError("Wait cluster start timeout")
          time.sleep(1)
  
file_path: mars/mars/deploy/utils.py
imports: import asyncio
  import os
  import time
  import warnings
  from typing import Callable, Dict, List, Union, TextIO
  import yaml
  from ..services import NodeRole
  from ..utils import merge_dict, flatten_dict_to_nested_dict
label_desc: Use image node_id 1 for calling a global function with example usage: wait_services_ready(selectors, min_counts, count_fun, timeout) without return types