tooz/examples/group_membership_watch.py
Julien Danjou fd368a706b doc: switch examples to Zake
This avoids having Zookeeper or memcached running, which might not be
the case.

Change-Id: Ib66eb8348aece447ee2c8de084c4ac807b552907
2014-11-18 15:39:05 +01:00

23 lines
491 B
Python

import uuid
import six
from tooz import coordination
coordinator = coordination.get_coordinator('zake://', b'host-1')
coordinator.start()
# Create a group
group = six.binary_type(six.text_type(uuid.uuid4()).encode('ascii'))
request = coordinator.create_group(group)
request.get()
def group_joined(event):
# Event is an instance of tooz.coordination.MemberJoinedGroup
print(event.group_id, event.member_id)
coordinator.watch_join_group(group, group_joined)
coordinator.stop()