I am able to get current contenders using election.lock._get_sorted_children() and respective identifiers using election.lock.contenders(). But election.lock.contenders() also sorts the list, so will election.lock.contenders()[0] always be the leader?
Note, election = zk.Election("/path", "uuid") where zk is the KazooClient
Is there any better way to verify the leader?
Kazoo follows zookepeers recommendation that the node with smallest index should acquire the lock. The
Lock::_inner_acquireensures that the lock is acquired by the smallest index, by always waiting for predecessors to finish before acquiring lock. Hence,election.lock.contenders()[0]will always be the leader (unless the list is empty of-course).