コード例 #1
0
ファイル: server.py プロジェクト: Delaunay/cqueue
    def _start(self, properties):
        kwargs = dict(args=' '.join([self.bin] + self.arguments),
                      stdout=subprocess.PIPE,
                      bufsize=1,
                      stderr=subprocess.STDOUT)
        self.cmd = kwargs['args']

        debug(self.cmd)
        with subprocess.Popen(**kwargs, shell=True) as proc:
            try:
                properties['running'] = True
                properties['pid'] = proc.pid

                while properties['running']:
                    if proc.poll() is None:
                        line = proc.stdout.readline().decode('utf-8')
                        if line:
                            self.parse(properties, line)
                    else:
                        properties['running'] = False
                        properties['exit'] = proc.returncode

            except Exception:
                error(traceback.format_exc())
                raise
コード例 #2
0
    def _run_local_query(self, statement):
        if isinstance(statement, str):
            statement = statement.encode('utf8')

        out = subprocess.check_output(
            f'{self.bin} sql --insecure --host={self.addrs}',
            input=statement,
            shell=True)
        debug(out.decode('utf8').strip())
コード例 #3
0
    def parse(self, properties, line):
        debug(line[:-1])

        if line[0] == '*':
            return
        try:
            a, b = line.split(':', maxsplit=1)
            properties[a.strip()] = b.strip()

        except Exception as e:
            print(e, line, end='\n')
            print(traceback.format_exc())
            raise RuntimeError(f'{line} (cmd: {self.cmd})')
コード例 #4
0
ファイル: server.py プロジェクト: Delaunay/cqueue
    def parse(self, properties, line):
        debug(line[40:-1])
        line = line.strip()
        # save the init logs for debugging
        if '[initandlisten]' in line:
            self.loglines.append(line)

        if line.endswith(f'waiting for connections on port {self.port}'):
            properties['ready'] = True

        if 'shutting down with code:0' in line:
            pass

        elif 'shutting down' in line:
            print('\n'.join(self.loglines))
            raise RuntimeError(f'Closing because: `{line}`')