当前位置: 首页>>代码示例>>Python>>正文


Python queue.Empty方法代码示例

本文整理汇总了Python中six.moves.queue.Empty方法的典型用法代码示例。如果您正苦于以下问题:Python queue.Empty方法的具体用法?Python queue.Empty怎么用?Python queue.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.queue的用法示例。


在下文中一共展示了queue.Empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_60_taskdone_failed_retry

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def test_60_taskdone_failed_retry(self):
        '''
        processing = [ test_project:taskid ]
        '''
        self.status_queue.put({
            'taskid': 'taskid',
            'project': 'test_project',
            'url': 'url',
            'track': {
                'fetch': {
                    'ok': True
                },
                'process': {
                    'ok': False
                },
            }
        })  # task retry 0/3 test_project:taskid url
        from six.moves import queue as Queue
        # with self.assertRaises(Queue.Empty):
            # task = self.scheduler2fetcher.get(timeout=4)
        task = self.scheduler2fetcher.get(timeout=5)  # select test_project:taskid url
        self.assertIsNotNone(task) 
开发者ID:binux,项目名称:pyspider,代码行数:24,代码来源:test_scheduler.py

示例2: run

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def run(self):
        '''Run loop'''
        logger.info("processor starting...")

        while not self._quit:
            try:
                task, response = self.inqueue.get(timeout=1)
                self.on_task(task, response)
                self._exceptions = 0
            except Queue.Empty as e:
                continue
            except KeyboardInterrupt:
                break
            except Exception as e:
                logger.exception(e)
                self._exceptions += 1
                if self._exceptions > self.EXCEPTION_LIMIT:
                    break
                continue

        logger.info("processor exiting...") 
开发者ID:binux,项目名称:pyspider,代码行数:23,代码来源:processor.py

示例3: get

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def get(self, block=True, timeout=None, ack=False):
        if not block:
            return self.get_nowait()

        start_time = time.time()
        while True:
            try:
                return self.get_nowait(ack)
            except BaseQueue.Empty:
                if timeout:
                    lasted = time.time() - start_time
                    if timeout > lasted:
                        time.sleep(min(self.max_timeout, timeout - lasted))
                    else:
                        raise
                else:
                    time.sleep(self.max_timeout) 
开发者ID:binux,项目名称:pyspider,代码行数:19,代码来源:rabbitmq.py

示例4: get

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def get(self, block=True, timeout=None):
        if not block:
            return self.get_nowait()

        start_time = time.time()
        while True:
            try:
                return self.get_nowait()
            except self.Empty:
                if timeout:
                    lasted = time.time() - start_time
                    if timeout > lasted:
                        time.sleep(min(self.max_timeout, timeout - lasted))
                    else:
                        raise
                else:
                    time.sleep(self.max_timeout) 
开发者ID:binux,项目名称:pyspider,代码行数:19,代码来源:redis_queue.py

示例5: get

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def get(self):
        '''Get a task from queue when bucket available'''
        if self.bucket.get() < 1:
            return None
        now = time.time()
        self.mutex.acquire()
        try:
            task = self.priority_queue.get_nowait()
            self.bucket.desc()
        except Queue.Empty:
            self.mutex.release()
            return None
        task.exetime = now + self.processing_timeout
        self.processing.put(task)
        self.mutex.release()
        return task.taskid 
开发者ID:binux,项目名称:pyspider,代码行数:18,代码来源:task_queue.py

示例6: _check_task_done

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def _check_task_done(self):
        '''Check status queue'''
        cnt = 0
        try:
            while True:
                task = self.status_queue.get_nowait()
                # check _on_get_info result here
                if task.get('taskid') == '_on_get_info' and 'project' in task and 'track' in task:
                    if task['project'] not in self.projects:
                        continue
                    project = self.projects[task['project']]
                    project.on_get_info(task['track'].get('save') or {})
                    logger.info(
                        '%s on_get_info %r', task['project'], task['track'].get('save', {})
                    )
                    continue
                elif not self.task_verify(task):
                    continue
                self.on_task_status(task)
                cnt += 1
        except Queue.Empty:
            pass
        return cnt 
开发者ID:binux,项目名称:pyspider,代码行数:25,代码来源:scheduler.py

示例7: run

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def run(self):
        '''Run loop'''
        logger.info("result_worker starting...")

        while not self._quit:
            try:
                task, result = self.inqueue.get(timeout=1)
                self.on_result(task, result)
            except Queue.Empty as e:
                continue
            except KeyboardInterrupt:
                break
            except AssertionError as e:
                logger.error(e)
                continue
            except Exception as e:
                logger.exception(e)
                continue

        logger.info("result_worker exiting...") 
开发者ID:binux,项目名称:pyspider,代码行数:22,代码来源:result_worker.py

示例8: _commit

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def _commit(self):
    bulk = []
    stop = False

    while True:
      while len(bulk) < 50 and not stop:
        try:
          obj = self.elastic_bulk.get(timeout=3)
        except queue.Empty:
          break

        if obj is None:
          stop = True
        else:
          bulk.append(obj)

      if bulk:
        try:
          self.helper.bulk(self.elastic, bulk)
        except Exception as err:
          LOGGER.exception('es index error: %s', err)
        bulk = []

      if stop:
        break 
开发者ID:pcbje,项目名称:gransk,代码行数:27,代码来源:es_index.py

示例9: generator

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def generator(self):
        while not self.closed:
            # Use a blocking get() to ensure there's at least one chunk of
            # data, and stop iteration if the chunk is None, indicating the
            # end of the audio stream.
            chunk = self._buff.get()
            if chunk is None:
                return
            data = [chunk]

            # Now consume whatever other data's still buffered.
            while True:
                try:
                    chunk = self._buff.get(block=False)
                    if chunk is None:
                        return
                    data.append(chunk)
                except queue.Empty:
                    break

            yield b''.join(data)
# [END audio_stream] 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:24,代码来源:_audio.py

示例10: generator

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def generator(self):
		while not self.closed:
			# Use a blocking get() to ensure there's at least one chunk of
			# data, and stop iteration if the chunk is None, indicating the
			# end of the audio stream.
			chunk = self._buff.get()
			if chunk is None:
				return
			data = [chunk]

			# Now consume whatever other data's still buffered.
			while True:
				try:
					chunk = self._buff.get(block=False)
					if chunk is None:
						return
					data.append(chunk)
				except queue.Empty:
					break

			yield b''.join(data)
# [END audio_stream] 
开发者ID:gigagenie,项目名称:ai-makers-kit,代码行数:24,代码来源:ex1_kwstest.py

示例11: generator

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def generator(self):
        while not self.closed:
            # Use a blocking get() to ensure there's at least one chunk of
            # data, and stop iteration if the chunk is None, indicating the
            # end of the audio stream.
            chunk = self._buff.get()
            if chunk is None:
                return
            data = [chunk]

            # Now consume whatever other data's still buffered.
            while True:
                try:
                    chunk = self._buff.get(block=False)
                    if chunk is None:
                        return
                    data.append(chunk)
                except queue.Empty:
                    break

            yield b''.join(data) 
开发者ID:piraka9011,项目名称:dialogflow_ros,代码行数:23,代码来源:AudioServerStream.py

示例12: fetch_batch

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def fetch_batch(self):
        """ Fetch a batch of data without waiting"""
        inp, f = self.queue.get()
        nr_input_var = len(inp)
        batched, futures = [[] for _ in range(nr_input_var)], []
        for k in range(nr_input_var):
            batched[k].append(inp[k])
        futures.append(f)
        cnt = 1
        while cnt < self.batch_size:
            try:
                inp, f = self.queue.get_nowait()
                for k in range(nr_input_var):
                    batched[k].append(inp[k])
                futures.append(f)
            except queue.Empty:
                break
            cnt += 1
        return batched, futures 
开发者ID:anonymous-author1,项目名称:DDRL,代码行数:21,代码来源:concurrency.py

示例13: consume_queue

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def consume_queue(queue, cascade_stop):
    """Consume the queue by reading lines off of it and yielding them."""
    while True:
        try:
            item = queue.get(timeout=0.1)
        except Empty:
            yield None
            continue
        # See https://github.com/docker/compose/issues/189
        except thread.error:
            raise ShutdownException()

        if item.exc:
            raise item.exc

        if item.is_stop and not cascade_stop:
            continue

        yield item.item 
开发者ID:QData,项目名称:deepWordBug,代码行数:21,代码来源:log_printer.py

示例14: consume_queue

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def consume_queue(queue, cascade_stop):
    """Consume the queue by reading lines off of it and yielding them."""
    while True:
        try:
            item = queue.get(timeout=0.1)
        except Empty:
            yield None
            continue
        # See https://github.com/docker/compose/issues/189
        except thread.error:
            raise ShutdownException()

        if item.exc:
            raise item.exc

        if item.is_stop:
            if cascade_stop:
                raise StopIteration
            else:
                continue

        yield item.item 
开发者ID:openai,项目名称:universe,代码行数:24,代码来源:log_printer.py

示例15: flush

# 需要导入模块: from six.moves import queue [as 别名]
# 或者: from six.moves.queue import Empty [as 别名]
def flush(self):
        """
        Drop any currently incoming messages and flush the received messages
        queue.
        """
        for _, drop_message in self.request_threads:
            drop_message.set()
            self.file_logger.debug("Request thread set to drop response.")

        timeout = time.time() + (5 * self.timeout)
        while not self.responses.empty() and time.time() < timeout:
            try:
                self.responses.get(block=False)
            except queue.Empty:
                self.file_logger.debug("Responses queue flushed.")
            else:
                self.responses.task_done() 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:19,代码来源:client.py


注:本文中的six.moves.queue.Empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。