Пример #1
0
    def call(self, name: str, codec_req: Codec, codec_resp: Codec,
             request: Any) -> Any:
        strC.encode(self.stdin, name)
        codec_req.encode(self.stdin, request)
        self.stdin.flush()

        try:
            while True:
                msg = MessageC.decode(self.stdout)
                #log.debug('message received: %s' % str(msg))

                if isinstance(msg, Progress):
                    log.debug('progress: %d' % msg.position)

                elif isinstance(msg, Log):
                    level = ['DEBUG', 'INFO', 'WARN', 'ERROR'][msg.level]
                    log.info('[%s] %s' % (level, msg.message))

                elif isinstance(msg, AnswerFollows):
                    return codec_resp.decode(self.stdout)

                elif isinstance(msg, Error):
                    raise Failure(msg.message, msg.extra)

                else:
                    raise MalformedResponse('invalid response: %s' % msg)
        except EOF as e:
            death_note = self.stderr_reader.get_content().decode('utf8')
            log.warn('core died with message: {0}'.format(death_note))
            raise CoreDeath(death_note)
        except CodecError as e:
            raise MalformedResponse('malformed response from core') from e
Пример #2
0
    def shutdown(self) -> None:
        log.debug('core shutdown')

        try:
            strC.encode(self.stdin, 'quit')
            self.stdin.flush()
        except (OSError, BrokenPipeError):  # windows throws OSError
            log.debug('could not send quit, the core is probably dead already')

        try:
            self.core.wait(2)  # seconds
        except subprocess.TimeoutExpired:
            log.warn("core won't quit, killing")
            self.core.terminate()

            try:
                self.core.wait(2)  # seconds
            except subprocess.TimeoutExpired:
                log.error(
                    "core does not respond to SIGTERM, sending SIGKILL and not waiting anymore"
                )
                self.core.kill()

        log.debug('waiting for stderr reader...')
        self.stderr_reader.join(1)  # join the stderr reader

        if self.stderr_reader.is_alive():
            log.warn("stderr reader won't quit, leaking it")
        else:
            log.debug('stderr reader joined')
Пример #3
0
    def save_to_file(self, worker: Worker, fname: str) -> None:
        with bz2.open(fname, 'wb') as f:
            f = cast(FileOut, f)  # assert we're doing output

            f.write(PREST_SIGNATURE)
            intC.encode(f, FILE_FORMAT_VERSION)  # version
            strC.encode(f, branding.VERSION)

            work_size = listCP(DatasetCP).get_size(self.datasets)
            intC.encode(f, work_size)

            worker.set_work_size(work_size)
            listCP(DatasetCP).encode(worker, f, self.datasets)