def waitListening(client=None, server='127.0.0.1', port=80, timeout=None):
 runCmd = (client.cmd if client else partial(quietRun, shell=True))
 if (not runCmd('which telnet')):
  raise Exception('Could not find telnet')
 serverIP = (server if isinstance(server, basestring) else server.IP())
 cmd = ('echo A | telnet -e A %s %s' % (serverIP, port))
 time = 0
 result = runCmd(cmd)
 while ('Connected' not in result):
  if ('No route' in result):
   rtable = runCmd('route')
   error(('no route to %s:\n%s' % (server, rtable)))
   return False
  if (timeout and (time >= timeout)):
   error(('could not connect to %s on port %d\n' % (server, port)))
   return False
  debug('waiting for', server, 'to listen on port', port, '\n')
  info('.')
  sleep(0.5)
  time += 0.5
  result = runCmd(cmd)
 return True

def waitListening ( client = None , server = '127.0.0.1' , port = 80 , timeout = None ) : runCmd = ( client . cmd if client else partial ( quietRun , shell = True ) ) if ( not runCmd ( 'which telnet' ) ) : raise Exception ( 'Could not find telnet' ) serverIP = ( server if isinstance ( server , basestring ) else server . IP ( ) ) cmd = ( 'echo A | telnet -e A %s %s' % ( serverIP , port ) ) time = 0 result = runCmd ( cmd ) while ( 'Connected' not in result ) : if ( 'No route' in result ) : rtable = runCmd ( 'route' ) error ( ( 'no route to %s:\n%s' % ( server , rtable ) ) ) return False if ( timeout and ( time >= timeout ) ) : error ( ( 'could not connect to %s on port %d\n' % ( server , port ) ) ) return False debug ( 'waiting for' , server , 'to listen on port' , port , '\n' ) info ( '.' ) sleep ( 0.5 ) time += 0.5 result = runCmd ( cmd ) return True
wait until server is listening on port .