Ejemplo n.º 1
0
    def _do_command(self, action, fields=None, timeout=None):
        if fields is None:
            fields = {}
        self._commands_executed += 1
        if timeout is None:
            timeout = self.command_timeout

        if not self._process_running:
            raise Exception('Plugin was stopped')

        with self._command_lock:
            command = self._create_command(action, fields)
            self._proc.stdin.write(PluginIPCStream.encode(command))
            self._proc.stdin.flush()

            try:
                response = self._response_queue.get(block=True, timeout=timeout)
                while response['cid'] != self._cid:
                    response = self._response_queue.get(block=False)
                exception = response.get('_exception')
                if exception is not None:
                    raise RuntimeError(exception)
                return response
            except Empty:
                self.logger('[Runner] No response within {0}s (action={1}, fields={2})'.format(timeout, action, fields))
                self._commands_failed += 1
                raise Exception('Plugin did not respond')
Ejemplo n.º 2
0
 def _write(msg):
     sys.stdout.write(PluginIPCStream.encode(msg))
     sys.stdout.flush()