本文整理汇总了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)
示例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...")
示例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)
示例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)
示例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
示例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
示例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...")
示例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
示例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]
示例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]
示例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)
示例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
示例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
示例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
示例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()