kazoo.handlers.threading

A threading based handler.

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

Warning

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.

Note

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

async_result()[source]

Create a AsyncResult instance

dispatch_callback(callback)[source]

Dispatch to the callback object

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

event_object()[source]

Create an appropriate Event object

lock_object()[source]

Create a lock object

queue_empty

alias of Empty

queue_impl

alias of Queue

rlock_object()[source]

Create an appropriate RLock object

static sleep_func()

sleep(seconds)

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

start()[source]

Start the worker threads.

stop()[source]

Stop the worker threads and empty all queues.

timeout_exception

alias of KazooTimeoutError

Private API

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

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