A threading based handler.

The SequentialThreadingHandler is intended for regular Python environments that use threads.


Do not use SequentialThreadingHandler with applications using asynchronous event loops (like gevent). Use the SequentialGeventHandler instead.

Public API

class kazoo.handlers.threading.SequentialThreadingHandler[source]

Threading handler for sequentially executing callbacks.

This handler executes callbacks in a sequential manner. A queue is created for each of the callback events, so that each type of event has its callback type run sequentially. These are split into two queues, one for watch events and one for async result completion callbacks.

Each queue type has a thread worker that pulls the callback event off the queue and runs it in the order the client sees it.

This split helps ensure that watch callbacks won’t block session re-establishment should the connection be lost during a Zookeeper client call.

Watch and completion callbacks should avoid blocking behavior as the next callback of that type won’t be run until it completes. If you need to block, spawn a new thread and return immediately so callbacks can proceed.


Completion callbacks can block to wait on Zookeeper calls, but no other completion callbacks will execute until the callback returns.


Create a AsyncResult instance


Dispatch to the callback object

The callback is put on separate queues to run depending on the type as documented for the SequentialThreadingHandler.


Create an appropriate Event object


Create a lock object


Create an appropriate RLock object



Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.


Start the worker threads.


Stop the worker threads and empty all queues.

Private API

class kazoo.handlers.threading.AsyncResult(handler)[source]

A one-time event that stores a value or an exception

get(block=True, timeout=None)[source]

Return the stored value or raise the exception.

If there is no value raises TimeoutError.


Return the value or raise the exception without blocking.

If nothing is available, raises TimeoutError

Register a callback to call when a value or an exception is set


Return true if and only if it holds a value or an exception


Store the value. Wake up the waiters.


Store the exception. Wake up the waiters.


Return true if and only if it is ready and holds a value

Remove the callback set by rawlink()


Block until the instance is ready.

exception kazoo.handlers.threading.TimeoutError[source]