code: def _wait_for_grid_models(grid, grid_id, models, grid_size):
      grid_in_progress = None
      times_waited = 0
      while (times_waited < 3000) and (
          grid_in_progress is None
          or len(grid_in_progress.model_ids) < models
      ):
          time.sleep(0.1)  # give it tome to train some models
          times_waited += 1
          try:
              grid_in_progress = h2o.get_grid(grid_id)
          except IndexError:
              if times_waited % 100 == 0:
                  print(
                      "%s not trained yet after %ss"
                      % (models, times_waited / 10)
                  )
      grid.cancel()
      grid = h2o.get_grid(grid_id)
      old_grid_model_count = len(grid.model_ids)
      print("Grid has %d models" % old_grid_model_count)
      assert (
          old_grid_model_count < grid_size
      ), "The full grid should not have finished yet."
      h2o.remove_all()
      time.sleep(5)
      return old_grid_model_count
  
file_path: h2o-3/h2o-py/tests/testdir_algos/grid/pyunit_grid_resume_with_recovery.py
imports: import sys
  import os
  import tempfile
  import time
  import numpy
  import h2o
  from tests import pyunit_utils
  from h2o.grid.grid_search import H2OGridSearch
  from h2o.estimators.gbm import H2OGradientBoostingEstimator
label_desc: Use image node_id 1 for calling a global function with example usage: _wait_for_grid_models(grid, grid_id, models, grid_size) and returns: old_grid_model_count