code: def wait_for_service_available(container, url, timeout):
      
      start = time.time()
      remaining = timeout
      while True:
          remaining = start + timeout - time.time()
          if remaining < 0:
              raise ServiceTimeout
          try:
              response = get(url,
                  timeout=min(remaining, REQUEST_TIMEOUT_SECONDS))
              if 500 <= response.status_code < 600:
                  return False
              return True
          except (ConnectionError, Timeout):
              pass
          if not inspect_container(container)['State']['Running']:
              return False
  
          remaining = start + timeout - time.time()
          delay = max(0, min(RETRY_DELAY_SECONDS, remaining))
          time.sleep(delay)
  
      raise ServiceTimeout
docs: Wait up to timeout seconds for service at host:port
      to start.
  
      Returns True if service becomes available, False if the
      container stops or raises ServiceTimeout if timeout is
      reached.