Ejemplo n.º 1
0
    def run(self):
        # Get the server port, spawning it if necessary
        server_port = get_server_port()
        if server_port == -1 or not Server.ping(server_port, timeout=5):
            if len(self.client.server_prefs):
                # Spawn the server
                logger.info("Client spawning Server...")
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(5)
                sock.bind(('localhost', 0))
                sock.listen(1)
                port = sock.getsockname()[1]
                args = self.client.server_prefs + (port, )
                code = "from envisage.plugins.remote_editor.communication." \
                    "server import main; main(r'%s', '%s', %i)" % args
                spawn_independent([sys.executable, '-c', code])

                # Await a reponse from the server
                try:
                    server, address = accept_no_intr(sock)
                    try:
                        command, arguments = receive(server)
                        if command == "__port__":
                            self.client._server_port = int(arguments)
                        else:
                            raise socket.error
                    finally:
                        # Use try...except to handle timeouts
                        try:
                            server.shutdown(socket.SHUT_RD)
                        except:
                            pass
                except socket.error, e:
                    logger.error(repr(e))
                    logger.error("Client spawned a non-responsive Server! " \
                                     "Unregistering...")
                    self.client.error = True
                    self.client.unregister()
                    return
                finally:
                    sock.close()
Ejemplo n.º 2
0
    def run(self):
        # Get the server port, spawning it if necessary
        server_port = get_server_port()
        if server_port == -1 or not Server.ping(server_port, timeout=5):
            if len(self.client.server_prefs):
                # Spawn the server
                logger.info("Client spawning Server...")
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.settimeout(5)
                sock.bind(('localhost', 0))
                sock.listen(1)
                port = sock.getsockname()[1]
                args = self.client.server_prefs + ( port, )
                code = "from envisage.plugins.remote_editor.communication." \
                    "server import main; main(r'%s', '%s', %i)" % args
                spawn_independent([sys.executable, '-c', code])

                # Await a reponse from the server
                try:
                    server, address = accept_no_intr(sock)
                    try:
                        command, arguments = receive(server)
                        if command == "__port__":
                            self.client._server_port = int(arguments)
                        else:
                            raise socket.error
                    finally:
                        # Use try...except to handle timeouts
                        try:
                            server.shutdown(socket.SHUT_RD)
                        except:
                            pass
                except socket.error, e:
                    logger.error(repr(e))
                    logger.error("Client spawned a non-responsive Server! " \
                                     "Unregistering...")
                    self.client.error = True
                    self.client.unregister()
                    return
                finally:
                    sock.close()
Ejemplo n.º 3
0
    def _spawn(self, object_type):
        """ Attempt to spawn an process according the specified type. Returns
            whether this was sucessful.
        """
        try:
            command = self.spawn_commands[object_type]
        except KeyError:
            msg = "No spawn command is defined for object type '%s'." \
                % object_type
            logger.warning(msg)
            return msg

        try:
            logging.info("Server spawning Client of type '%s.'" % object_type)
            spawn_independent(command, shell=True)
        except OSError:
            msg = "Error spawning process for '%s' with command '%s'." \
                % (object_type, command)
            logger.error(msg)
            return msg

        return False
Ejemplo n.º 4
0
    def _spawn(self, object_type):
        """ Attempt to spawn an process according the specified type. Returns
            whether this was sucessful.
        """
        try:
            command = self.spawn_commands[object_type]
        except KeyError:
            msg = "No spawn command is defined for object type '%s'." \
                % object_type
            logger.warning(msg)
            return msg

        try:
            logging.info("Server spawning Client of type '%s.'" % object_type)
            spawn_independent(command, shell=True)
        except OSError:
            msg = "Error spawning process for '%s' with command '%s'." \
                % (object_type, command)
            logger.error(msg)
            return msg

        return False