def next(self):
        while self._index < len(self.item_ids)-1:
            self._index += 1
            # always destroy self.item to close file if necessary
            if getattr(self, 'item', None) is not None:
                del self.item
            if self.host:
                host = self.item_ids[self._index][0]
                item = self.item_ids[self._index][1]
            else:
                host = None
                item = self.item_ids[self._index]
            if not self.ignore_down and is_down(self.queue) and ( not host or
                    host_is_down(self.queue, host)):
                raise FSQDownError(errno.EAGAIN, u'queue {0}: is'\
                                   u' down'.format(self.queue))
            try:
                self.item = FSQWorkItem(self.queue,
                                        item,
                                        lock=self.lock, ttl=self.ttl,
                                        max_tries=self.max_tries,
                                        no_open=self.no_open,
                                        host=host)
            except (FSQWorkItemError, FSQCannotLockError, ), e:
                # we discard on ENOENT -- e.g. something else already did the
                #  work
                # or EAGAIN -- e.g. cannot lock because something else is
                #  already doing the work
                if e.errno == errno.EAGAIN or e.errno == errno.ENOENT:
                    continue
                # else raise
                raise e
            return self.item

        if getattr(self, 'item', None) is not None:
            del self.item
        # if we break through loop with no exception, we're done
        raise StopIteration()
dataset/ETHPy150Open axialmarket/fsq/fsq/scan.py/FSQScanGenerator.next/original