def wait_for_service_available(container, url, timeout):
start = time.time()<EOL>remaining = timeout<EOL>while True:<EOL><INDENT>remaining = start + timeout - time.time()<EOL>if remaining < <NUM_LIT:0>:<EOL><INDENT>raise ServiceTimeout<EOL><DEDENT>try:<EOL><INDENT>response = get(url,<EOL>timeout=min(remaining, REQUEST_TIMEOUT_SECONDS))<EOL>if <NUM_LIT> <= response.status_code < <NUM_LIT>:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL><DEDENT>except (ConnectionError, Timeout):<EOL><INDENT>pass<EOL><DEDENT>if not inspect_container(container)['<STR_LIT>']['<STR_LIT>']:<EOL><INDENT>return False<EOL><DEDENT>remaining = start + timeout - time.time()<EOL>delay = max(<NUM_LIT:0>, min(RETRY_DELAY_SECONDS, remaining))<EOL>time.sleep(delay)<EOL><DEDENT>raise ServiceTimeout<EOL>
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.