我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用gobject.IO_ERR。
def _register_io_handlers(self): def handler(source, cond): if cond & gobject.IO_IN: if not self.fifo: self.fifo = open(self.fifo_name, "w") self.fifo.write(source.recv(1024)) return True else: self.log.debug("Error communicating with MPlayer") return False flags = gobject.IO_IN | gobject.IO_ERR | gobject.IO_HUP self.io_watcher_id = gobject.io_add_watch(self.data, flags, handler) # _register_io_handlers()
def _get_mask(self, obj): mask = 0 if obj.readable(): mask |= gobject.IO_IN | gobject.IO_PRI if obj.writable(): mask |= gobject.IO_OUT # Only watch for errors if the socket is either readable or writable if mask: mask |= gobject.IO_ERR | gobject.IO_HUP | gobject.IO_NVAL return mask
def _register_io_handlers(self): flags_err = gobject.IO_ERR | gobject.IO_HUP def handler(fd, flags): if flags & flags_err: return False else: while self.playing: line = self._readline() if not line: return True elif line[:2] == "A:" and line[-1] =="\r": pieces = line.split() pos = float(pieces[1]) self.emit("pos", pos) return True elif line == "Exiting... (Quit)\n": self.proc.wait() self.proc = None self.emit("eos") self.emit("state-changed", PlayerEngine.STATE_NONE) return False elif line == "Starting playback...\n": # make buffer empty while line: line = self._readline(100) if line and line[:2] == "A:" and line[-1] == "\r": break self.set_volume(self.volume) self.set_mute(self.mute) self.set_fullscreen(self.fullscreen) self._query_media_info() self._register_state_timeout() self.emit("state-changed", PlayerEngine.STATE_PLAYING) return True else: self.log.debug("Ignored MPlayer output: %r" % line) return True flags = gobject.IO_IN | gobject.IO_PRI | flags_err self.out_watcher = gobject.io_add_watch(self.proc.stdout, flags, handler) # _register_io_handlers()