@gen.coroutine
def wait_for_http_server(url, timeout=10):
 loop = ioloop.IOLoop.current()
 tic = loop.time()
 client = AsyncHTTPClient()
 while ((loop.time() - tic) < timeout):
  try:
   r = (yield client.fetch(url, follow_redirects=False))
  except HTTPError as e:
   if (e.code >= 500):
    if (e.code != 599):
     app_log.warning('Server at %s responded with error: %s', url, e.code)
    (yield gen.sleep(0.1))
   else:
    app_log.debug('Server at %s responded with %s', url, e.code)
    return
  except (OSError, socket.error) as e:
   if (e.errno not in {errno.ECONNABORTED, errno.ECONNREFUSED, errno.ECONNRESET}):
    app_log.warning('Failed to connect to %s (%s)', url, e)
   (yield gen.sleep(0.1))
  else:
   return
 raise TimeoutError("Server at {url} didn't respond in {timeout} seconds".format(**locals()))

@ gen . coroutine def wait_for_http_server ( url , timeout = 10 ) : loop = ioloop . IOLoop . current ( ) tic = loop . time ( ) client = AsyncHTTPClient ( ) while ( ( loop . time ( ) - tic ) < timeout ) : try : r = ( yield client . fetch ( url , follow_redirects = False ) ) except HTTPError as e : if ( e . code >= 500 ) : if ( e . code != 599 ) : app_log . warning ( 'Server at %s responded with error: %s' , url , e . code ) ( yield gen . sleep ( 0.1 ) ) else : app_log . debug ( 'Server at %s responded with %s' , url , e . code ) return except ( OSError , socket . error ) as e : if ( e . errno not in { errno . ECONNABORTED , errno . ECONNREFUSED , errno . ECONNRESET } ) : app_log . warning ( 'Failed to connect to %s (%s)' , url , e ) ( yield gen . sleep ( 0.1 ) ) else : return raise TimeoutError ( "Server at {url} didn't respond in {timeout} seconds" . format ( ** locals ( ) ) )
wait for an http server to respond at url any non-5xx response code will do .