本文整理汇总了Python中queue.Empty方法的典型用法代码示例。如果您正苦于以下问题:Python queue.Empty方法的具体用法?Python queue.Empty怎么用?Python queue.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类queue
的用法示例。
在下文中一共展示了queue.Empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reset
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def reset(self):
"""
Resets the generator by stopping all processes
"""
self.alive.value = False
qsize = 0
try:
while True:
self.queue.get(timeout=0.1)
qsize += 1
except QEmptyExcept:
pass
print("Queue size on reset: {}".format(qsize))
for i, p in enumerate(self.proc):
p.join()
self.proc.clear()
示例2: extractInfo
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def extractInfo(self):
try:
while not self.exit:
try:
frame = self.frame_queue.get(block=True, timeout=1)
except queue.Empty:
print("Queue empty")
continue
try:
# Publish new image
msg = self.bridge.cv2_to_imgmsg(frame, 'rgb8')
if not self.exit:
self.image_publisher.publish(msg)
except CvBridgeError as e:
print("Error Converting cv image: {}".format(e.message))
self.frame_num += 1
except Exception as e:
print("Exception after loop: {}".format(e))
raise
示例3: _check_and_execute
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def _check_and_execute(self):
wakeup_queue = self._wakeup_queue
while 1:
(next_expired_time, expired_timers) = self._get_expired_timers()
for timer in expired_timers:
try:
# Note, please make timer callback effective/short
timer()
except Exception:
logging.error(traceback.format_exc())
self._reset_timers(expired_timers)
sleep_time = _calc_sleep_time(next_expired_time)
try:
wakeup = wakeup_queue.get(timeout=sleep_time)
if wakeup is TEARDOWN_SENTINEL:
break
except Queue.Empty:
pass
logging.info('TimerQueue stopped.')
示例4: _do_admin
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def _do_admin(self):
admin_q = self._admin_queue
resize_win = self._resize_window
while 1:
try:
wakup = admin_q.get(timeout=resize_win + 1)
except queue.Empty:
self._do_resize_according_to_loads()
continue
if wakup is None:
break
else:
self._do_resize_according_to_loads()
log.logger.info("ThreadPool admin thread=%s stopped.",
threading.current_thread().getName())
示例5: get
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def get(self, timeout=None):
"""
Return the result when it arrives. If timeout is not None and the
result does not arrive within timeout seconds then
multiprocessing.TimeoutError is raised. If the remote call raised an
exception then that exception will be reraised by get().
"""
try:
res = self._q.get(timeout=timeout)
except queue.Empty:
raise multiprocessing.TimeoutError("Timed out")
if isinstance(res, Exception):
raise res
return res
示例6: run
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def run(self):
window_name = "Olympe Streaming Example"
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
main_thread = next(
filter(lambda t: t.name == "MainThread", threading.enumerate())
)
while main_thread.is_alive():
with self.flush_queue_lock:
try:
yuv_frame = self.frame_queue.get(timeout=0.01)
except queue.Empty:
continue
try:
self.show_yuv_frame(window_name, yuv_frame)
except Exception:
# We have to continue popping frame from the queue even if
# we fail to show one frame
traceback.print_exc()
finally:
# Don't forget to unref the yuv frame. We don't want to
# starve the video buffer pool
yuv_frame.unref()
cv2.destroyWindow(window_name)
示例7: _loop_for_observer
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def _loop_for_observer(self):
"""
Loop to pass data (put by method feed) to observer.
:return: None
"""
while self._request_end is False:
try:
data, timestamp = self._queue.get(True, self._timeout_for_get_from_queue)
try:
self.logger.log(level=TRACE, msg=r'notifying {}({!r})'.format(self._observer, repr(data)))
except ReferenceError:
self._request_end = True # self._observer is no more valid.
try:
if self._observer_self:
self._observer(self._observer_self, data, timestamp)
else:
self._observer(data, timestamp)
except ReferenceError:
self._request_end = True # self._observer is no more valid.
except Exception:
self.logger.exception(msg=r'Exception inside: {}({!r})'.format(self._observer, repr(data)))
except queue.Empty:
pass # No incoming data within self._timeout_for_get_from_queue
self._observer = None
self._observer_self = None
示例8: worker
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def worker(work_queue, results_queue, throttle):
while True:
try:
item = work_queue.get(block=False)
except Empty:
break
else:
while not throttle.consume():
pass
try:
result = fetch_place(item)
except Exception as err:
results_queue.put(err)
else:
results_queue.put(result)
finally:
work_queue.task_done()
开发者ID:PacktPublishing,项目名称:Expert-Python-Programming_Second-Edition,代码行数:21,代码来源:threads_exceptions_and_throttling.py
示例9: display
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def display(self):
if os.getpid() != self._creator:
return
while not self._stop:
lines_displayed = 0
while True:
try:
line = self._stream.get_nowait()
sys.stdout.write(line)
lines_displayed += 1
except Empty:
break
if self._stop or lines_displayed > self._max_lines_displayed:
break
else:
await asyncio.sleep(0)
sys.stdout.flush()
if not self._stop:
await cancellable_sleep(self._interval)
示例10: test_run_empty
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def test_run_empty(self, m_count):
events = [(x, (), {}) for x in (mock.sentinel.event1,
mock.sentinel.event2)]
group = mock.sentinel.group
m_queue = mock.Mock()
m_queue.empty.return_value = True
m_queue.get.side_effect = events + [queue.Empty()]
m_handler = mock.Mock()
m_count.return_value = list(range(5))
async_handler = h_async.Async(m_handler, mock.Mock(), mock.Mock())
with mock.patch('time.sleep'):
async_handler._run(group, m_queue)
m_handler.assert_has_calls([mock.call(event[0]) for event in events])
self.assertEqual(len(events), m_handler.call_count)
示例11: install_pyro_queue_callback
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def install_pyro_queue_callback(self):
"""
Add a callback to the tkinter event loop that is invoked every so often.
The callback checks the Pyro work queue for work and processes it.
"""
def check_pyro_queue():
try:
while True:
# get a work item from the queue (until it is empty)
workitem = self.pyro_queue.get_nowait()
# execute it in the gui's mainloop thread
workitem["callable"](*workitem["vargs"], **workitem["kwargs"])
except queue.Empty:
pass
self.tk.after(1000 // PYRO_QUEUE_HZ, check_pyro_queue)
self.tk.after(1000 // PYRO_QUEUE_HZ, check_pyro_queue)
示例12: api
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def api(self, request, data=None):
log.debug('api: %s, %s', request, data)
msg = {
'req': request.lower(),
'data': data,
'sender': 'RemoteServer'}
self.q_send.put(msg)
try:
status, data = self.q_recv.get(timeout=5)
except queue.Empty:
status, data = False, 'Timeout waiting for response.'
return flask.jsonify({
'status': status,
'msg': 'OK' if status else data,
'data': data if status else None,
})
示例13: handle_output
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def handle_output(self) -> None:
"""Handles output from stream.
"""
while self.is_alive():
try:
order_books = self._output_queue.get(
block=True, timeout=self.streaming_timeout
)
except queue.Empty: # todo snap every 5s or so anyway
if self.flumine.markets.live_orders:
order_books = self._listener.snap(
market_ids=self.flumine.markets.open_market_ids
)
else:
continue
if order_books:
self.flumine.handler_queue.put(CurrentOrdersEvent(order_books))
logger.info("Stopped output_thread (OrderStream {0})".format(self.stream_id))
示例14: handle_output
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def handle_output(self) -> None:
"""Handles output from stream.
"""
while self.is_alive():
try:
market_books = self._output_queue.get(
block=True, timeout=self.streaming_timeout
)
except queue.Empty:
market_books = self._listener.snap(
market_ids=self.flumine.markets.open_market_ids
)
if market_books:
self.flumine.handler_queue.put(MarketBookEvent(market_books))
logger.info("Stopped output_thread (MarketStream {0})".format(self.stream_id))
示例15: download_worker_function
# 需要导入模块: import queue [as 别名]
# 或者: from queue import Empty [as 别名]
def download_worker_function(download_queue, vtapikey):
while True:
try:
sha256 = download_queue.get()
except queue.Empty:
continue
if sha256 == "STOP":
download_queue.task_done()
return True
print("{} downloading".format(sha256))
sample_path = os.path.join(samples_path, sha256)
success = vt_download_sample(sha256, sample_path, vtapikey)
if not success:
print("{} had a problem".format(sha256))
print("{} done".format(sha256))
download_queue.task_done()