Exemple #1
0
    def run_with_handles(self):
        self.child = subprocess.Popen(self.args,
                                      bufsize=1,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE)
        alive = True

        while True:
            (rds, wds,
             xds) = select.select([self.child.stdout, self.child.stderr], [],
                                  [], 1)

            if self.child.stdout in rds:
                line = self.child.stdout.readline()
                self.captured_stdout.append(compat.str(line))

            if self.child.stderr in rds:
                line = self.child.stderr.readline()
                self.captured_stderr.append(compat.str(line))

            if self.should_die.is_set():
                self.child.terminate()
                alive = False

            poll_results = self.child.poll()
            if poll_results is not None:
                if not alive:
                    break
                else:
                    self.dump_logs()
                    raise RuntimeError(
                        "Subprocess has died. Aborting. (args=%s)" %
                        ' '.join(str(x) for x in self.args))
Exemple #2
0
    def run_with_handles(self):
        self.child = subprocess.Popen(
            self.args,
            bufsize=1,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        alive = True

        while True:
            (rds, wds, xds) = select.select([self.child.stdout, self.child.stderr], [], [], 1)

            if self.child.stdout in rds:
                line = self.child.stdout.readline()
                self.captured_stdout.append(compat.str(line))

            if self.child.stderr in rds:
                line = self.child.stderr.readline()
                self.captured_stderr.append(compat.str(line))

            if self.should_die.is_set():
                self.child.terminate()
                alive = False

            poll_results = self.child.poll()
            if poll_results is not None:
                if not alive:
                    break
                else:
                    self.dump_logs()
                    raise RuntimeError("Subprocess has died. Aborting. (args=%s)" % ' '.join(str(x) for x in self.args))
Exemple #3
0
def read_short_string(data, cur):
    if len(data) < cur + 2:
        raise BufferUnderflowError("Not enough data left")

    (strlen,) = struct.unpack('>h', data[cur:cur + 2])
    if strlen == -1:
        return None, cur + 2

    cur += 2
    if len(data) < cur + strlen:
        raise BufferUnderflowError("Not enough data left")

    out = data[cur:cur + strlen]
    return compat.str(out), cur + strlen
Exemple #4
0
def read_short_string(data, cur):
    if len(data) < cur + 2:
        raise BufferUnderflowError("Not enough data left")

    (strlen, ) = struct.unpack('>h', data[cur:cur + 2])
    if strlen == -1:
        return None, cur + 2

    cur += 2
    if len(data) < cur + strlen:
        raise BufferUnderflowError("Not enough data left")

    out = data[cur:cur + strlen]
    return compat.str(out), cur + strlen
Exemple #5
0
    def decode_produce_response(cls, data):
        """
        Decode bytes to a ProduceResponse

        Params
        ======
        data: bytes to decode
        """
        ((correlation_id, num_topics), cur) = relative_unpack('>ii', data, 0)

        for i in range(num_topics):
            ((strlen,), cur) = relative_unpack('>h', data, cur)
            topic = compat.str(data[cur:cur + strlen])
            cur += strlen
            ((num_partitions,), cur) = relative_unpack('>i', data, cur)
            for i in range(num_partitions):
                ((partition, error, offset), cur) = relative_unpack('>ihq',
                                                                    data, cur)

                yield ProduceResponse(topic, partition, error, offset)