(self, port, timeout=uconf.SERVER_TIMEOUT)
Waits until port is open on this instance.
        This is a useful way to check if the system has booted and the HTTP server is running.
Waits until port is open on this instance.
        This is a useful way to check if the system has booted and the HTTP server is running.
Waits until port is open on this instance . This is a useful way to check if the system has booted and the HTTP server is running .
def wait_for_port(self, port, timeout=uconf.SERVER_TIMEOUT):
        """Waits until port is open on this instance.
        This is a useful way to check if the system has booted and the HTTP server is running.
        """
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(timeout)
        start = datetime.datetime.now()
        print ">> waiting for port", port

        if not self.get_ip():
            raise Exception("Error getting IP for this instance. Instance must have an IP before calling this method.")

        while True:
            # We need this try block because depending on the parameters the system will cause the connection
            # to timeout early.
            try:
                if sock.connect_ex((self.get_ip(), port)):
                    # we got a connection, lets return
                    return
                else:
                    time.sleep(3)
            except:
                # TODO: catch the timeout exception and ignore that, but every other exception should be raised
                # The system timeout, no problem
                pass

            if (datetime.datetime.now() - start).seconds > timeout:
                print (datetime.datetime.now() - start).seconds
                raise Exception("Connection timed out. Try increasing the timeout amount, or fix your server.")

        print ">> port %s is live" % (port)
def wait_for_port ( self , port , timeout = uconf . SERVER_TIMEOUT ) : sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) sock . settimeout ( timeout ) start = datetime . datetime . now ( ) print ">> waiting for port" , port if not self . get_ip ( ) : raise Exception ( "Error getting IP for this instance. Instance must have an IP before calling this method." ) while True : # We need this try block because depending on the parameters the system will cause the connection # to timeout early. try : if sock . connect_ex ( ( self . get_ip ( ) , port ) ) : # we got a connection, lets return return else : time . sleep ( 3 ) except : # TODO: catch the timeout exception and ignore that, but every other exception should be raised # The system timeout, no problem pass if ( datetime . datetime . now ( ) - start ) . seconds > timeout : print ( datetime . datetime . now ( ) - start ) . seconds raise Exception ( "Connection timed out. Try increasing the timeout amount, or fix your server." ) print ">> port %s is live" % ( port )