本文整理匯總了Python中kazoo.protocol.connection.ConnectionHandler.stop方法的典型用法代碼示例。如果您正苦於以下問題:Python ConnectionHandler.stop方法的具體用法?Python ConnectionHandler.stop怎麽用?Python ConnectionHandler.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類kazoo.protocol.connection.ConnectionHandler
的用法示例。
在下文中一共展示了ConnectionHandler.stop方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: KazooClient
# 需要導入模塊: from kazoo.protocol.connection import ConnectionHandler [as 別名]
# 或者: from kazoo.protocol.connection.ConnectionHandler import stop [as 別名]
class KazooClient(object):
"""An Apache Zookeeper Python client supporting alternate callback
handlers and high-level functionality.
Watch functions registered with this class will not get session
events, unlike the default Zookeeper watches. They will also be
called with a single argument, a
:class:`~kazoo.protocol.states.WatchedEvent` instance.
"""
def __init__(self, hosts='127.0.0.1:2181',
timeout=10.0, client_id=None, handler=None,
default_acl=None, auth_data=None, read_only=None,
randomize_hosts=True, connection_retry=None,
command_retry=None, logger=None, **kwargs):
"""Create a :class:`KazooClient` instance. All time arguments
are in seconds.
:param hosts: Comma-separated list of hosts to connect to
(e.g. 127.0.0.1:2181,127.0.0.1:2182,[::1]:2183).
:param timeout: The longest to wait for a Zookeeper connection.
:param client_id: A Zookeeper client id, used when
re-establishing a prior session connection.
:param handler: An instance of a class implementing the
:class:`~kazoo.interfaces.IHandler` interface
for callback handling.
:param default_acl: A default ACL used on node creation.
:param auth_data:
A list of authentication credentials to use for the
connection. Should be a list of (scheme, credential)
tuples as :meth:`add_auth` takes.
:param read_only: Allow connections to read only servers.
:param randomize_hosts: By default randomize host selection.
:param connection_retry:
A :class:`kazoo.retry.KazooRetry` object to use for
retrying the connection to Zookeeper. Also can be a dict of
options which will be used for creating one.
:param command_retry:
A :class:`kazoo.retry.KazooRetry` object to use for
the :meth:`KazooClient.retry` method. Also can be a dict of
options which will be used for creating one.
:param logger: A custom logger to use instead of the module
global `log` instance.
Basic Example:
.. code-block:: python
zk = KazooClient()
zk.start()
children = zk.get_children('/')
zk.stop()
As a convenience all recipe classes are available as attributes
and get automatically bound to the client. For example::
zk = KazooClient()
zk.start()
lock = zk.Lock('/lock_path')
.. versionadded:: 0.6
The read_only option. Requires Zookeeper 3.4+
.. versionadded:: 0.6
The retry_max_delay option.
.. versionadded:: 0.6
The randomize_hosts option.
.. versionchanged:: 0.8
Removed the unused watcher argument (was second argument).
.. versionadded:: 1.2
The connection_retry, command_retry and logger options.
"""
self.logger = logger or log
# Record the handler strategy used
self.handler = handler if handler else SequentialThreadingHandler()
if inspect.isclass(self.handler):
raise ConfigurationError("Handler must be an instance of a class, "
"not the class: %s" % self.handler)
self.auth_data = auth_data if auth_data else set([])
self.default_acl = default_acl
self.randomize_hosts = randomize_hosts
self.hosts = None
self.chroot = None
self.set_hosts(hosts)
# Curator like simplified state tracking, and listeners for
# state transitions
self._state = KeeperState.CLOSED
self.state = KazooState.LOST
self.state_listeners = set()
self._reset()
self.read_only = read_only
#.........這裏部分代碼省略.........
示例2: KazooClient
# 需要導入模塊: from kazoo.protocol.connection import ConnectionHandler [as 別名]
# 或者: from kazoo.protocol.connection.ConnectionHandler import stop [as 別名]
class KazooClient(object):
"""An Apache Zookeeper Python client supporting alternate callback
handlers and high-level functionality.
Watch functions registered with this class will not get session
events, unlike the default Zookeeper watches. They will also be
called with a single argument, a
:class:`~kazoo.protocol.states.WatchedEvent` instance.
"""
def __init__(self, hosts='127.0.0.1:2181', watcher=None,
timeout=10.0, client_id=None, max_retries=None, retry_delay=0.1,
retry_backoff=2, retry_jitter=0.8, handler=None,
default_acl=None, auth_data=None, read_only=None):
"""Create a :class:`KazooClient` instance. All time arguments
are in seconds.
:param hosts: Comma-separated list of hosts to connect to
(e.g. 127.0.0.1:2181,127.0.0.1:2182).
:param watcher:
Set a default watcher. This will be called by the actual
default watcher that :class:`KazooClient` establishes.
:param timeout: The longest to wait for a Zookeeper connection.
:param client_id: A Zookeeper client id, used when
re-establishing a prior session connection.
:param max_retries: Maximum retries when using the
:meth:`KazooClient.retry` method.
:param retry_delay: Initial delay when retrying a call.
:param retry_backoff:
Backoff multiplier between retry attempts. Defaults to 2
for exponential back-off.
:param retry_jitter:
How much jitter delay to introduce per call. An amount of
time up to this will be added per retry call to avoid
hammering the server.
:param handler: An instance of a class implementing the
:class:`~kazoo.interfaces.IHandler` interface
for callback handling.
:param default_acl: A default ACL used on node creation.
:param auth_data:
A list of authentication credentials to use for the
connection. Should be a list of (scheme, credential)
tuples as :meth:`add_auth` takes.
Retry parameters will be used for connection establishment
attempts and reconnects.
Basic Example:
.. code-block:: python
zk = KazooClient()
zk.start()
children = zk.get_children('/')
zk.stop()
As a convenience all recipe classes are available as attributes
and get automatically bound to the client. For example::
zk = KazooClient()
zk.start()
lock = zk.Lock('/lock_path')
"""
self.log_debug = logging.DEBUG >= log.getEffectiveLevel()
# Record the handler strategy used
self.handler = handler if handler else SequentialThreadingHandler()
if inspect.isclass(self.handler):
raise ConfigurationError("Handler must be an instance of a class, "
"not the class: %s" % self.handler)
self.auth_data = auth_data if auth_data else set([])
self.default_acl = default_acl
self.hosts, chroot = collect_hosts(hosts)
if chroot:
self.chroot = normpath(chroot)
else:
self.chroot = ''
# Curator like simplified state tracking, and listeners for
# state transitions
self._state_lock = self.handler.rlock_object()
self._state = KeeperState.CLOSED
self.state = KazooState.LOST
self.state_listeners = set()
self._reset()
self.read_only = read_only
if client_id:
self._session_id = client_id[0]
self._session_passwd = client_id[1]
else:
self._session_id = None
self._session_passwd = str(bytearray([0] * 16))
# ZK uses milliseconds
self._session_timeout = int(timeout * 1000)
#.........這裏部分代碼省略.........