ZooKeeper Leader Elections
- class kazoo.recipe.election.Election(client, path, identifier=None)¶
Kazoo Basic Leader Election
Example usage with a KazooClient instance:zk = KazooClient() zk.start() election = zk.Election("/electionpath", "my-identifier") # blocks until the election is won, then calls # my_leader_function() election.run(my_leader_function)
- __init__(client, path, identifier=None)¶
Create a Kazoo Leader Election
- client – A KazooClient instance.
- path – The election path to use.
- identifier – Name to use for this lock contender. This can be useful for querying to see who the current lock contenders are.
Cancel participation in the election
If this contender has already been elected leader, this method will not interrupt the leadership function.
Return an ordered list of the current contenders in the election
If the contenders did not set an identifier, it will appear as a blank string.
- run(func, *args, **kwargs)¶
Contend for the leadership
This call will block until either this contender is cancelled or this contender wins the election and the provided leadership function subsequently returns or fails.
- func – A function to be called if/when the election is won.
- args – Arguments to leadership function.
- kwargs – Keyword arguments to leadership function.