zktools.connection

Zookeeper Connection Classes

Connection Class

class zktools.connection.ZkConnection(host='localhost:2181', connect_timeout=10, session_timeout=10000, reconnect_timeout=10000, debug=False)[source]

Zookeeper Connection object

__init__(host='localhost:2181', connect_timeout=10, session_timeout=10000, reconnect_timeout=10000, debug=False)[source]

Create a connection object, capable of automatically reconnecting when the connection is lost.

In the event the connection is lost, the zookeeper command will block until the connection is available again, or the reconnect_timeout is reached. The latter will raise an Exception about the reconnect period expiring.

Example:

conn = ZkConnection()
conn.connect()

node = conn.create(
    "/my/node", "a value",
    [{"perms": 0x1f, "scheme": "world", "id": "anyone"}],
    0)

Note

ZkConnection ensures that all zookeeper functions use the same zookeeper handle that ZkConnection has, so it does not need to be passed in as the first argument.

Parameters:
  • host – A valid zookeeper host string
  • connect_timeout (int) – Timeout for connecting to zookeeper
  • session_timeout (int) – Timeout for the zookeeper session
  • reconnect_timeout (int) – How many seconds to attempt to reconnect before giving up. Set to 0 to avoid reconnect attempts.
connect()[source]

Connect to zookeeper

__getattr__(name)[source]

Returns a reconnecting version that also uses the current handle

Table Of Contents

Previous topic

API Documentation

Next topic

zktools.locking

This Page