- interface kazoo.interfaces.IHandler¶
A Callback Handler for Zookeeper completion and watch callbacks
This object must implement several methods responsible for determining how completion / watch callbacks are handled as well as the method for calling IAsyncResult callback functions.
These functions are used to abstract differences between a Python threading environment and asynchronous single-threaded environments like gevent. The minimum functionality needed for Kazoo to handle these differences is encompassed in this interface.
The Handler should document how callbacks are called for:
- Zookeeper completion events
- Zookeeper watch events
- spawn(func, *args, **kwargs)¶
Spawn a function to run asynchronously
- args – args to call the function with.
- kwargs – keyword args to call the function with.
This method should return immediately and execute the function with the provided args and kwargs in an asynchronous manner.
Dispatch to the callback object
Parameters: callback – A Callback object to be called.
Human readable name of the Handler interface
Return an appropriate object that implements Python’s threading.RLock API
Stop the handler. Should block until the handler is safely stopped.
Appropriate sleep function that can be called with a single argument and sleep.
Return an appropriate object that implements Python’s threading.Event API
A socket method that implements Python’s socket.create_connection API
Start the handler, used for setting up the handler.
Return an appropriate object that implements Python’s threading.Lock API
Exception class that should be thrown and captured if a result is not available within the given time
Return an instance that conforms to the IAsyncResult interface appropriate for this handler
A select method that implements Python’s select.select API
A socket method that implements Python’s socket.socket API
The IAsyncResult documents the proper implementation for providing a value that results from a Zookeeper completion callback. Since the KazooClient returns an IAsyncResult object instead of taking a completion callback for async functions, developers wishing to have their own callback called should use the IAsyncResult.rawlink() method.
- interface kazoo.interfaces.IAsyncResult¶
An Async Result object that can be queried for a value that has been set asynchronously
This object is modeled on the gevent AsyncResult object.
Store the value. Wake up the waiters.
Parameters: value – Value to store as the result.
Return the value or raise the exception without blocking.
If nothing is available, raise the Timeout exception class on the associated IHandler interface.
Store the exception. Wake up the waiters.
Parameters: exception – Exception to raise when fetching the value.
Return True if and only if it is ready and holds a value
- get(block=True, timeout=None)¶
Return the stored value or raise the exception
- block (bool) – Whether this method should block or return immediately.
- timeout (float) – How long to wait for a value when block is True.
Register a callback to call when a value or an exception is set
Parameters: callback (func) – A callback function to call after set() or set_exception() has been called. This function will be passed a single argument, this instance.
Return True if and only if it holds a value or an exception
Remove the callback set by rawlink()
Parameters: callback (func) – A callback function to remove.
Block until the instance is ready.
Parameters: timeout (float) – How long to wait for a value when block is True.