def fetch(self):
        children = sorted(self.zk.get_children(self.root), \
            lambda a, b: cmp(a['path'], b['path']))

        if not children:
            return None

        try:
            first = children[0]
            self.zk.delete(first['path'], version=first['version'])
            if 'data64' not in first:
                return ''
            else:
                return first['data64'].decode('base64')

        except (ZooKeeper.WrongVersion, ZooKeeper.NotFound):
            # someone changed the znode between the get and delete
            # this should not happen
            # in practice you should retry the fetch
            raise
Pull an element from the queue
dataset/ETHPy150Open andreisavu/zookeeper-mq/experiments/rest/demo_queue.py/Queue.fetch