本文整理汇总了Python中work_queue.WorkQueue.is_queue_empty方法的典型用法代码示例。如果您正苦于以下问题:Python WorkQueue.is_queue_empty方法的具体用法?Python WorkQueue.is_queue_empty怎么用?Python WorkQueue.is_queue_empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类work_queue.WorkQueue
的用法示例。
在下文中一共展示了WorkQueue.is_queue_empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SandeshSession
# 需要导入模块: from work_queue import WorkQueue [as 别名]
# 或者: from work_queue.WorkQueue import is_queue_empty [as 别名]
class SandeshSession(TcpSession):
_KEEPALIVE_IDLE_TIME = 45 # in secs
_KEEPALIVE_INTERVAL = 3 # in secs
_KEEPALIVE_PROBES = 5
def __init__(self, sandesh_instance, server, event_handler, sandesh_msg_handler):
self._sandesh_instance = sandesh_instance
self._logger = sandesh_instance._logger
self._event_handler = event_handler
self._reader = SandeshReader(self, sandesh_msg_handler)
self._writer = SandeshWriter(self)
self._send_queue = WorkQueue(self._send_sandesh, self._is_ready_to_send_sandesh)
TcpSession.__init__(self, server)
# end __init__
# Public functions
def sandesh_instance(self):
return self._sandesh_instance
# end sandesh_instance
def is_send_queue_empty(self):
return self._send_queue.is_queue_empty()
# end is_send_queue_empty
def is_connected(self):
return self._connected
# end is_connected
def enqueue_sandesh(self, sandesh):
self._send_queue.enqueue(sandesh)
# end enqueue_sandesh
def send_queue(self):
return self._send_queue
# end send_queue
# Overloaded functions from TcpSession
def connect(self):
TcpSession.connect(self, timeout=5)
# end connect
def _on_read(self, buf):
if self._reader.read_msg(buf) < 0:
self._logger.error("SandeshReader Error. Close Collector session")
self.close()
# end _on_read
def _handle_event(self, event):
self._event_handler(self, event)
# end _handle_event
def _set_socket_options(self):
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if hasattr(socket, "TCP_KEEPIDLE"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, self._KEEPALIVE_IDLE_TIME)
if hasattr(socket, "TCP_KEEPALIVE"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, self._KEEPALIVE_IDLE_TIME)
if hasattr(socket, "TCP_KEEPINTVL"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, self._KEEPALIVE_INTERVAL)
if hasattr(socket, "TCP_KEEPCNT"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, self._KEEPALIVE_PROBES)
# end _set_socket_options
# Private functions
def _send_sandesh(self, sandesh):
if self._send_queue.is_queue_empty():
more = False
else:
more = True
if not self._connected:
self._logger.log(SandeshLogger.get_py_logger_level(sandesh.level()), sandesh.log())
return
if sandesh.is_logging_allowed(self._sandesh_instance):
self._logger.log(SandeshLogger.get_py_logger_level(sandesh.level()), sandesh.log())
self._writer.send_msg(sandesh, more)
# end _send_sandesh
def _is_ready_to_send_sandesh(self):
return self._sandesh_instance.is_send_queue_enabled()
示例2: SandeshSession
# 需要导入模块: from work_queue import WorkQueue [as 别名]
# 或者: from work_queue.WorkQueue import is_queue_empty [as 别名]
class SandeshSession(TcpSession):
_KEEPALIVE_IDLE_TIME = 15 # in secs
_KEEPALIVE_INTERVAL = 3 # in secs
_KEEPALIVE_PROBES = 5
_TCP_USER_TIMEOUT_OPT = 18
_TCP_USER_TIMEOUT_VAL = 30000 # ms
def __init__(self, sandesh_instance, server, event_handler, sandesh_msg_handler):
self._sandesh_instance = sandesh_instance
self._logger = sandesh_instance._logger
self._event_handler = event_handler
self._reader = SandeshReader(self, sandesh_msg_handler)
self._writer = SandeshWriter(self)
self._send_queue = WorkQueue(self._send_sandesh, self._is_ready_to_send_sandesh)
TcpSession.__init__(self, server)
# end __init__
# Public functions
def sandesh_instance(self):
return self._sandesh_instance
# end sandesh_instance
def is_send_queue_empty(self):
return self._send_queue.is_queue_empty()
# end is_send_queue_empty
def is_connected(self):
return self._connected
# end is_connected
def enqueue_sandesh(self, sandesh):
self._send_queue.enqueue(sandesh)
# end enqueue_sandesh
def send_queue(self):
return self._send_queue
# end send_queue
# Overloaded functions from TcpSession
def connect(self):
TcpSession.connect(self, timeout=5)
# end connect
def _on_read(self, buf):
if self._reader.read_msg(buf) < 0:
self._logger.error("SandeshReader Error. Close Collector session")
self.close()
# end _on_read
def _handle_event(self, event):
self._event_handler(self, event)
# end _handle_event
def _set_socket_options(self):
self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if hasattr(socket, "TCP_KEEPIDLE"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, self._KEEPALIVE_IDLE_TIME)
if hasattr(socket, "TCP_KEEPALIVE"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, self._KEEPALIVE_IDLE_TIME)
if hasattr(socket, "TCP_KEEPINTVL"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, self._KEEPALIVE_INTERVAL)
if hasattr(socket, "TCP_KEEPCNT"):
self._socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, self._KEEPALIVE_PROBES)
try:
self._socket.setsockopt(socket.IPPROTO_TCP, self._TCP_USER_TIMEOUT_OPT, self._TCP_USER_TIMEOUT_VAL)
except:
self._logger.error(
"setsockopt failed: option %d, value %d" % (self._TCP_USER_TIMEOUT_OPT, self._TCP_USER_TIMEOUT_VAL)
)
# end _set_socket_options
# Private functions
def _send_sandesh(self, sandesh):
if self._send_queue.is_queue_empty():
more = False
else:
more = True
if not self._connected:
if self._sandesh_instance.is_logging_dropped_allowed(sandesh):
self._logger.error("SANDESH: %s: %s" % ("Not connected", sandesh.log()))
self._sandesh_instance.msg_stats().update_tx_stats(
sandesh.__class__.__name__, 0, SandeshTxDropReason.SessionNotConnected
)
return
if sandesh.is_logging_allowed(self._sandesh_instance):
self._logger.log(SandeshLogger.get_py_logger_level(sandesh.level()), sandesh.log())
self._writer.send_msg(sandesh, more)
#.........这里部分代码省略.........