Skip to content
Browse files

Log errors in gevent callbacks

  • Loading branch information...
1 parent a44e4f6 commit 99a96d7d05c0f80e687ddee91382ff61880eae3a @labisso labisso committed Jun 4, 2012
Showing with 26 additions and 1 deletion.
  1. +3 −1 kazoo/sync/sync_gevent.py
  2. +23 −0 kazoo/test/test_zkclient.py
View
4 kazoo/sync/sync_gevent.py
@@ -1,5 +1,6 @@
import fcntl
import os
+import logging
import gevent
import gevent.event
@@ -9,6 +10,7 @@
import kazoo.sync.util
realthread = kazoo.sync.util.get_realthread()
+log = logging.getLogger(__name__)
# this is inspired by the threadpool recipe in the geventutil package:
# https://bitbucket.org/denis/gevent-playground/src/tip/geventutil/threadpool.py
@@ -114,7 +116,7 @@ def _cb_thread(self):
try:
fun(*args)
except Exception:
- pass
+ log.exception("Exception in kazoo callback")
self._cb_fun = None
self._cb_args = None
View
23 kazoo/test/test_zkclient.py
@@ -76,6 +76,29 @@ def w(watch_event):
event.wait(1)
self.assertTrue(event.is_set())
+ def test_exists_watcher_exception(self):
+ self.client.connect()
+ self.client.ensure_path("/")
+
+ nodepath = "/" + uuid.uuid4().hex
+
+ event = threading.Event()
+
+ # if the watcher throws an exception, all we can really do is log it
+ def w(watch_event):
+ self.assertEqual(watch_event.path, nodepath)
+ event.set()
+
+ raise Exception("this is really bad")
+
+ exists = self.zk.exists(nodepath, watch=w)
+ self.assertIsNone(exists)
+
+ self.zk.create(nodepath, "x", ephemeral=True)
+
+ event.wait(1)
+ self.assertTrue(event.is_set())
+
def test_create_delete(self):
self.client.connect()
self.client.ensure_path("/")

0 comments on commit 99a96d7

Please sign in to comment.
Something went wrong with that request. Please try again.