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


alias of Empty


alias of Queue


Create an appropriate RLock object

static sleep_func()


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.


alias of KazooTimeoutError

Private API

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

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