Utility functions for Zookeeper
Safely call a function while handling connection loss
This function merely retries the query until an active Zookeeper session is available that returns without throwing a ConnectionLoss Exception. When creating a node, this could result in a NodeAlreadyExists exception because the create ran twice.
Safely creates an ephemeral sequence node using a UUID prefix
This function properly handles zookeeper ConnectionLoss exceptions and determines after waiting for reconnection whether it was created successfully.
Name of the created node
The name will be split so that its prefixed by the UUID and suffixed by the sequence.
>>> safe_create_ephemeral_sequence(zk, '/path/to/node/myname', [ZOO_OPEN_ACL_UNSAFE]) '/path/to/node/dfad3fa294d745e499d883b0a38bbc93-myname-0001'
Decorator to run a function in a separate thread
|Parameters:||func – Function to run in the other thread|
@threaded def task1(): do_something @threaded def task2(): do_something_too t1 = task1() t2 = task2() ... t1.join() t2.join()