本文整理匯總了Python中pool.Pool.check方法的典型用法代碼示例。如果您正苦於以下問題:Python Pool.check方法的具體用法?Python Pool.check怎麽用?Python Pool.check使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pool.Pool
的用法示例。
在下文中一共展示了Pool.check方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: EtcdClient
# 需要導入模塊: from pool import Pool [as 別名]
# 或者: from pool.Pool import check [as 別名]
class EtcdClient(object):
"""The etcd client
"""
logger = logging.getLogger('etcd2')
def __init__(self, node, timeout = None, checkInterval = DEFAULT_CHECK_INTERVAL, errorCallback = None):
"""Create a new EtcdClient
Parameters:
node The initialized etcd node, could be the following values:
- A host
- A list of host
- A tuple (host, port)
- A list of tuple (host, port)
- The pool.Node object
- A list of pool.Node object
checkInterval The pool node checking interval in ms, None will disable the node checking
"""
# Parse the node into a list of pool.Node object
if not node:
raise ValueError('Invalid node [%s]' % node)
nodes = []
if isinstance(node, list):
# A node list
for n in node:
if isinstance(n, Node):
nodes.append(n)
else:
nodes.append(Node.load(n))
else:
# A single node
if isinstance(node, Node):
nodes.append(Node)
else:
nodes.append(Node.load(node))
# Set attributes
self.timeout = timeout
self.errorCallback = errorCallback
# Create the pool
self._pool = Pool(self, nodes, timeout = timeout or DEFAULT_TIMEOUT)
# Create the channel
self._channel = self.__createchannel__()
# Create the dispatcher
self._dispatcher = self.__createdispatcher__()
# Dispatch background jobs
self._dispatcher.timer(self.__backgroundpoolchecking__, checkInterval)
# Create APIs
self.cluster = ClusterAPI(self)
self.keys = KeysAPI(self)
def __createchannel__(self):
"""Create the etcd channel
"""
raise NotImplementedError
def __createdispatcher__(self):
"""Create the dispatcher
"""
raise NotImplementedError
def __onerror__(self, action, params, error, traceback):
"""On error happened
Parameters:
action The error action
params The action parameters
error The exception object
traceback The traceback string
Returns:
Nothing
"""
def __backgroundpoolchecking__(self):
"""The backgound pool checking job
"""
self.logger.debug('Start background checking')
self._pool.check()
@property
def pool(self):
"""Return the pool
"""
return self._pool
@property
def channel(self):
"""Return the channel
"""
return self._channel
@property
def dispatcher(self):
"""Return the dispatcher
"""
return self._dispatcher