'Handle one request on the queue.
Raises StopIndexing exception if iteration should stop.'

def _iteration(self):

    if (self.mode == self.MODE_DAEMON):
        (priority, timestamp, request) = self._requests.get()
    else:
        (priority, timestamp, request) = self._requests.get_nowait()
    try:
        if (request.priority == PRIORITY_CONTROL):
            if isinstance(request, IndexerStopRequest):
                raise self.StopIndexing()
            elif isinstance(request, IndexerPauseRequest):
                self._pauseEvent.set()
                self._resumeEvent.wait()
                return
            else:
                raise CodeIntelError(('unexpected    indexer    control    request:    %r' % request))
        if isinstance(request, ScanRequest):
            db = self.mgr.db
            buf = request.buf
            status = 'changed'
            if (not request.force):
                scan_time_in_db = db.get_buf_scan_time(buf)
                if ((scan_time_in_db is not None) and (scan_time_in_db > request.mtime)):
                    log.debug('indexer:    drop    %s:    have    up-to-date    data    for    %s    in    the    db', request, buf)
                    status = 'skipped'
                    return
            buf.scan(mtime=request.mtime)
        elif isinstance(request, XMLParseRequest):
            request.buf.xml_parse()
        elif isinstance(request, CullMemRequest):
            log.debug('cull    memory    requested')
            self.mgr.db.cull_mem()
        elif isinstance(request, PreloadBufLibsRequest):
            for lib in request.buf.libs:
                if isinstance(lib, (LangDirsLib, MultiLangDirsLib)):
                    lib.ensure_all_dirs_scanned()
        elif isinstance(request, PreloadLibRequest):
            lib = request.lib
            assert isinstance(lib, (LangDirsLib, MultiLangDirsLib))
            lib.ensure_all_dirs_scanned()
        if ((not isinstance(request, CullMemRequest)) and (self.mode == self.MODE_DAEMON)):
            log.debug('staging    new    cull    mem    request')
            self.stage_request(CullMemRequest(), 300)
        self.mgr.db.report_event(None)
    finally:
        if isinstance(request, ScanRequest):
            request.complete(status)
            if self.on_scan_complete:
                try:
                    self.on_scan_complete(request)
                except:
                    log.exception('ignoring    exception    in    Indexer    on_scan_complete    callback')
