Exemple #1
0
    def execute(self, local=False, debug=False):
        """
        Triggers the program execution.

        The environment will execute all parts of the program that have resulted in a "sink" operation.
        """
        if debug:
            local = True
        self._local_mode = local
        self._debug_mode = debug
        self._optimize_plan()

        plan_mode = sys.stdin.readline().rstrip('\n') == "plan"

        if plan_mode:
            port = int(sys.stdin.readline().rstrip('\n'))
            self._connection = Connection.PureTCPConnection(port)
            self._iterator = Iterator.PlanIterator(self._connection, self)
            self._collector = Collector.PlanCollector(self._connection, self)
            self._send_plan()
            result = self._receive_result()
            self._connection.close()
            return result
        else:
            import struct
            operator = None
            try:
                port = int(sys.stdin.readline().rstrip('\n'))

                id = int(sys.stdin.readline().rstrip('\n'))
                input_path = sys.stdin.readline().rstrip('\n')
                output_path = sys.stdin.readline().rstrip('\n')

                used_set = None
                operator = None
                for set in self._sets:
                    if set.id == id:
                        used_set = set
                        operator = set.operator
                operator._configure(input_path, output_path, port, self,
                                    used_set)
                operator._go()
                operator._close()
                sys.stdout.flush()
                sys.stderr.flush()
            except:
                sys.stdout.flush()
                sys.stderr.flush()
                if operator is not None:
                    operator._connection._socket.send(struct.pack(">i", -2))
                else:
                    socket = SOCKET.socket(family=SOCKET.AF_INET,
                                           type=SOCKET.SOCK_STREAM)
                    socket.connect((SOCKET.gethostbyname("localhost"), port))
                    socket.send(struct.pack(">i", -2))
                    socket.close()
                raise
Exemple #2
0
    def execute(self, local=False):
        """
        Triggers the program execution.

        The environment will execute all parts of the program that have resulted in a "sink" operation.
        """
        self._optimize_plan()

        if self._container.is_planning():
            port = int(sys.stdin.readline().rstrip('\n'))
            self._connection = Connection.PureTCPConnection(port)
            self._iterator = Iterator.PlanIterator(self._connection, self)
            self._collector = Collector.PlanCollector(self._connection, self)
            self._send_plan()
            result = self._receive_result()
            self._connection.close()
            return result
        else:
            import struct
            operator = None
            port = None
            try:
                if self._container.should_execute(self):
                    id = int(sys.stdin.readline().rstrip('\n'))

                    port = int(sys.stdin.readline().rstrip('\n'))
                    subtask_index = int(sys.stdin.readline().rstrip('\n'))
                    mmap_size = int(sys.stdin.readline().rstrip('\n'))
                    input_path = sys.stdin.readline().rstrip('\n')
                    output_path = sys.stdin.readline().rstrip('\n')

                    used_set = None
                    operator = None

                    for set in self._sets:
                        if set.id == id:
                            used_set = set
                            operator = set.operator
                    operator._configure(input_path, output_path, mmap_size,
                                        port, self, used_set, subtask_index)
                    operator._go()
                    operator._close()
                    sys.stdout.flush()
                    sys.stderr.flush()
            except:
                sys.stdout.flush()
                sys.stderr.flush()
                if operator is not None and operator._connection is not None:
                    operator._connection._socket.send(struct.pack(">i", -2))
                elif port is not None:
                    socket = SOCKET.socket(family=SOCKET.AF_INET,
                                           type=SOCKET.SOCK_STREAM)
                    socket.connect((SOCKET.gethostbyname("localhost"), port))
                    socket.send(struct.pack(">i", -2))
                    socket.close()
                raise