def _get_members(p): if not p.exists(encoded_group): raise coordination.GroupNotCreated(group_id) potential_members = set() for m in p.hkeys(encoded_group): m = self._decode_member_id(m) if m != self.GROUP_EXISTS: potential_members.add(m) if not potential_members: return set() # Ok now we need to see which members have passed away... gone_members = set() member_values = p.mget( compat_map(self._encode_beat_id, potential_members)) for (potential_member, value) in compat_zip(potential_members, member_values): # Always preserve self (just incase we haven't heartbeated # while this call/s was being made...), this does *not* prevent # another client from removing this though... if potential_member == self._member_id: continue if not value: gone_members.add(potential_member) # Trash all the members that no longer are with us... RIP... if gone_members: p.multi() encoded_gone_members = list( self._encode_member_id(m) for m in gone_members) p.hdel(encoded_group, *encoded_gone_members) p.execute() return set(m for m in potential_members if m not in gone_members) return potential_members
def _get_members(p): if not p.exists(encoded_group): raise coordination.GroupNotCreated(group_id) potential_members = [] for m in p.hkeys(encoded_group): m = self._decode_member_id(m) if m != self.GROUP_EXISTS: potential_members.append(m) if not potential_members: return [] # Ok now we need to see which members have passed away... gone_members = set() member_values = p.mget(compat_map(self._encode_beat_id, potential_members)) for (potential_member, value) in compat_zip(potential_members, member_values): # Always preserve self (just incase we haven't heartbeated # while this call/s was being made...), this does *not* prevent # another client from removing this though... if potential_member == self._member_id: continue if not value: gone_members.add(potential_member) # Trash all the members that no longer are with us... RIP... if gone_members: p.multi() encoded_gone_members = list(self._encode_member_id(m) for m in gone_members) p.hdel(encoded_group, *encoded_gone_members) p.execute() return list(m for m in potential_members if m not in gone_members) else: return potential_members
def get_duplicate_keys(iterable, key=None): if key is not None: iterable = compat_map(key, iterable) keys = set() duplicates = set() for item in iterable: if item in keys: duplicates.add(item) keys.add(item) return duplicates
def execute(self, *args, **kwargs): l = [kwargs[r] for r in self.requires] return list(compat_map(self._functor, l))