implementation.rst 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. .. _implementation_details:
  2. ======================
  3. Implementation Details
  4. ======================
  5. Up to version 0.3 kazoo used the Python bindings to the Zookeeper C library.
  6. Unfortunately those bindings are fairly buggy and required a fair share of
  7. weird workarounds to interface with the native OS thread used in those
  8. bindings.
  9. Starting with version 0.4 kazoo implements the entire Zookeeper wire protocol
  10. itself in pure Python. Doing so removed the need for the workarounds and made
  11. it much easier to implement the features missing in the C bindings.
  12. Handlers
  13. ========
  14. Both the Kazoo handlers run 3 separate queues to help alleviate deadlock issues
  15. and ensure consistent execution order regardless of environment. The
  16. :class:`~kazoo.handlers.gevent.SequentialGeventHandler` runs a separate
  17. greenlet for each queue that processes the callbacks queued in order. The
  18. :class:`~kazoo.handlers.threading.SequentialThreadingHandler` runs a separate
  19. thread for each queue that processes the callbacks queued in order (thus the
  20. naming scheme which notes they are sequential in anticipation that there could
  21. be handlers shipped in the future which don't make this guarantee).
  22. Callbacks are queued by type, the 3 types being:
  23. 1. Session events (State changes, registered listener functions)
  24. 2. Watch events (Watch callbacks, DataWatch, and ChildrenWatch functions)
  25. 3. Completion callbacks (Functions chained to
  26. :class:`~kazoo.interfaces.IAsyncResult` objects)
  27. This ensures that calls can be made to Zookeeper from any callback **except for
  28. a state listener** without worrying that critical session events will be
  29. blocked.
  30. .. warning::
  31. Its important to remember that if you write code that blocks in one of
  32. these functions then no queued functions of that type will be executed
  33. until the code stops blocking. If your code might block, it should run
  34. itself in a separate greenlet/thread so that the other callbacks can
  35. run.