def watch_once(self, key, timeout=None, **kwargs):
"""
Watch a key and stops after the first event.
If the timeout was specified and event didn't arrived method
will raise ``WatchTimedOut`` exception.
:param key: key to watch
:param timeout: (optional) timeout in seconds.
:returns: ``Event``
"""
event_queue = queue.Queue()
def callback(event):
event_queue.put(event)
watch_id = self.add_watch_callback(key, callback, **kwargs)
try:
return event_queue.get(timeout=timeout)
except queue.Empty:
raise exceptions.WatchTimedOut()
finally:
self.cancel_watch(watch_id)
评论列表
文章目录