def _elog_output_handler(self, fd, event): output = None if event & self.scheduler.IO_IN: try: output = os.read(fd, self._bufsize) except OSError as e: if e.errno not in (errno.EAGAIN, errno.EINTR): raise if output: lines = _unicode_decode(output).split('\n') if len(lines) == 1: self._buf += lines[0] else: lines[0] = self._buf + lines[0] self._buf = lines.pop() out = io.StringIO() for line in lines: funcname, phase, key, msg = line.split(' ', 3) self._elog_keys.add(key) reporter = getattr(portage.elog.messages, funcname) reporter(msg, phase=phase, key=key, out=out) if event & self.scheduler.IO_HUP: self.scheduler.source_remove(self._elog_reg_id) self._elog_reg_id = None os.close(self._elog_reader_fd) self._elog_reader_fd = None return False return True
def _input_handler(self, fd, event): # Read the whole pickle in a single atomic read() call. data = None if event & PollConstants.POLLIN: # For maximum portability, use os.read() here since # array.fromfile() and file.read() are both known to # erroneously return an empty string from this # non-blocking fifo stream on FreeBSD (bug #337465). try: data = os.read(fd, self._bufsize) except OSError as e: if e.errno != errno.EAGAIN: raise # Assume that another event will be generated # if there's any relevant data. if data: try: obj = pickle.loads(data) except SystemExit: raise except Exception: # The pickle module can raise practically # any exception when given corrupt data. pass else: self._reopen_input() cmd_key = obj[0] cmd_handler = self.commands[cmd_key] reply = cmd_handler(obj) try: self._send_reply(reply) except OSError as e: if e.errno == errno.ENXIO: # This happens if the client side has been killed. pass else: raise # Allow the command to execute hooks after its reply # has been sent. This hook is used by the 'exit' # command to kill the ebuild process. For some # reason, the ebuild-ipc helper hangs up the # ebuild process if it is waiting for a reply # when we try to kill the ebuild process. reply_hook = getattr(cmd_handler, 'reply_hook', None) if reply_hook is not None: reply_hook()
def _output_handler(self, f, event): buf = None if event & self.scheduler.IO_IN: try: buf = os.read(self._files['pipe_read'], self._bufsize) except OSError as e: if e.errno not in (errno.EAGAIN,): raise if buf: self._unregister() self.returncode = os.EX_OK self.wait() return True
def step_1(): A = [1, 2, 3] B = A[::-1] for i in A: print(i) for i in B: print(i) h, w = map(int, sys.stdin.readline().split()) print(h, w) input = map(int, os.read(0, 10000).split()) for i in input: print(i)
def _output_handler(self, fd, event): if event & self.scheduler.IO_IN: while True: try: self._raw_metadata.append( os.read(self._files.ebuild, self._bufsize)) except OSError as e: if e.errno not in (errno.EAGAIN,): raise break else: if not self._raw_metadata[-1]: self._unregister() self.wait() break self._unregister_if_appropriate(event) return True
def _input_handler(self, fd, event): # Read the whole pickle in a single atomic read() call. data = None if event & self.scheduler.IO_IN: # For maximum portability, use os.read() here since # array.fromfile() and file.read() are both known to # erroneously return an empty string from this # non-blocking fifo stream on FreeBSD (bug #337465). try: data = os.read(fd, self._bufsize) except OSError as e: if e.errno != errno.EAGAIN: raise # Assume that another event will be generated # if there's any relevant data. if data: try: obj = pickle.loads(data) except SystemExit: raise except Exception: # The pickle module can raise practically # any exception when given corrupt data. pass else: self._reopen_input() cmd_key = obj[0] cmd_handler = self.commands[cmd_key] reply = cmd_handler(obj) try: self._send_reply(reply) except OSError as e: if e.errno == errno.ENXIO: # This happens if the client side has been killed. pass else: raise # Allow the command to execute hooks after its reply # has been sent. This hook is used by the 'exit' # command to kill the ebuild process. For some # reason, the ebuild-ipc helper hangs up the # ebuild process if it is waiting for a reply # when we try to kill the ebuild process. reply_hook = getattr(cmd_handler, 'reply_hook', None) if reply_hook is not None: reply_hook() elif event & self.scheduler.IO_HUP: # This can be triggered due to a race condition which happens when # the previous _reopen_input() call occurs before the writer has # closed the pipe (see bug #401919). It's not safe to re-open # without a lock here, since it's possible that another writer will # write something to the pipe just before we close it, and in that # case the write will be lost. Therefore, try for a non-blocking # lock, and only re-open the pipe if the lock is acquired. lock_filename = os.path.join(os.path.dirname(self.input_fifo), '.ipc_lock') try: lock_obj = lockfile(lock_filename, unlinkfile=True, flags=os.O_NONBLOCK) except TryAgain: # We'll try again when another IO_HUP event arrives. pass else: try: self._reopen_input() finally: unlockfile(lock_obj) return True
def _input_handler(self, fd, event): # Read the whole pickle in a single atomic read() call. data = None if event & self.scheduler.IO_IN: # For maximum portability, use os.read() here since # array.fromfile() and file.read() are both known to # erroneously return an empty string from this # non-blocking fifo stream on FreeBSD (bug #337465). try: data = os.read(fd, self._bufsize) except OSError as e: if e.errno != errno.EAGAIN: raise # Assume that another event will be generated # if there's any relevant data. if data: try: obj = pickle.loads(data) except SystemExit: raise except Exception: # The pickle module can raise practically # any exception when given corrupt data. pass else: self._reopen_input() cmd_key = obj[0] cmd_handler = self.commands[cmd_key] reply = cmd_handler(obj) try: self._send_reply(reply) except OSError as e: if e.errno == errno.ENXIO: # This happens if the client side has been killed. pass else: raise # Allow the command to execute hooks after its reply # has been sent. This hook is used by the 'exit' # command to kill the ebuild process. For some # reason, the ebuild-ipc helper hangs up the # ebuild process if it is waiting for a reply # when we try to kill the ebuild process. reply_hook = getattr(cmd_handler, 'reply_hook', None) if reply_hook is not None: reply_hook() elif event & self.scheduler.IO_HUP: # This can be triggered due to a race condition which happens when # the previous _reopen_input() call occurs before the writer has # closed the pipe (see bug #401919). It's not safe to re-open # without a lock here, since it's possible that another writer will # write something to the pipe just before we close it, and in that # case the write will be lost. Therefore, try for a non-blocking # lock, and only re-open the pipe if the lock is acquired. lock_filename = os.path.join( os.path.dirname(self.input_fifo), '.ipc_lock') try: lock_obj = lockfile(lock_filename, unlinkfile=True, flags=os.O_NONBLOCK) except TryAgain: # We'll try again when another IO_HUP event arrives. pass else: try: self._reopen_input() finally: unlockfile(lock_obj) return True