def _receive_reply(self, input_fd): start_time = time.time() pipe_reader = PipeReader(input_files={"input_fd": input_fd}, scheduler=global_event_loop()) pipe_reader.start() eof = pipe_reader.poll() is not None while not eof: pipe_reader._wait_loop(timeout=self._COMMUNICATE_RETRY_TIMEOUT) eof = pipe_reader.poll() is not None if not eof: if self._daemon_is_alive(): self._timeout_retry_msg( start_time, portage.localization._("during read")) else: pipe_reader.cancel() self._no_daemon_msg() return 2 buf = pipe_reader.getvalue() retval = 2 if not buf: portage.util.writemsg_level( "ebuild-ipc: %s\n" % (portage.localization._("read failed"), ), level=logging.ERROR, noiselevel=-1, ) else: try: reply = pickle.loads(buf) except SystemExit: raise except Exception as e: # The pickle module can raise practically # any exception when given corrupt data. portage.util.writemsg_level("ebuild-ipc: %s\n" % (e, ), level=logging.ERROR, noiselevel=-1) else: (out, err, retval) = reply if out: portage.util.writemsg_stdout(out, noiselevel=-1) if err: portage.util.writemsg(err, noiselevel=-1) return retval
def _receive_reply(self, input_fd): start_time = time.time() pipe_reader = PipeReader(input_files={"input_fd":input_fd}, scheduler=global_event_loop()) pipe_reader.start() eof = pipe_reader.poll() is not None while not eof: pipe_reader._wait_loop(timeout=self._COMMUNICATE_RETRY_TIMEOUT) eof = pipe_reader.poll() is not None if not eof: if self._daemon_is_alive(): self._timeout_retry_msg(start_time, portage.localization._('during read')) else: pipe_reader.cancel() self._no_daemon_msg() return 2 buf = pipe_reader.getvalue() retval = 2 if not buf: portage.util.writemsg_level( "ebuild-ipc: %s\n" % \ (portage.localization._('read failed'),), level=logging.ERROR, noiselevel=-1) else: try: reply = pickle.loads(buf) except SystemExit: raise except Exception as e: # The pickle module can raise practically # any exception when given corrupt data. portage.util.writemsg_level( "ebuild-ipc: %s\n" % (e,), level=logging.ERROR, noiselevel=-1) else: (out, err, retval) = reply if out: portage.util.writemsg_stdout(out, noiselevel=-1) if err: portage.util.writemsg(err, noiselevel=-1) return retval
class _Reader(object): def __init__(self, future, input_file, loop): self._future = future self._pipe_reader = PipeReader(input_files={'input_file': input_file}, scheduler=loop) self._future.add_done_callback(self._cancel_callback) self._pipe_reader.addExitListener(self._eof) self._pipe_reader.start() def _cancel_callback(self, future): if future.cancelled(): self._cancel() def _eof(self, pipe_reader): self._pipe_reader = None self._future.set_result(pipe_reader.getvalue()) def _cancel(self): if self._pipe_reader is not None and self._pipe_reader.poll() is None: self._pipe_reader.removeExitListener(self._eof) self._pipe_reader.cancel() self._pipe_reader = None