<commit_before>import logging

from kazoo.exceptions import BadVersionError

from pykit import txutil

from .zkconf import kazoo_client_ext

logger = logging.getLogger(__name__)


def cas_loop(zkclient, path, json=True):

    zkclient, owning_zk = kazoo_client_ext(zkclient, json=json)

    def setter(path, val, zstat):
        try:
            zkclient.set(path, val, version=zstat.version)
            return True

        except BadVersionError as e:
            logger.info(repr(e) + ' concurrent updated to ' + repr(path))
            return False

    try:
        for curr in txutil.cas_loop(zkclient.get, setter, path):
            yield curr
    finally:<commit_msg>M  zkutil/zkacid.py<commit_after>import logging

from kazoo.exceptions import BadVersionError

from pykit import txutil

from .zkconf import kazoo_client_ext

logger = logging.getLogger(__name__)


def cas_loop(zkclient, path, json=True):

    zkclient, owning_zk = kazoo_client_ext(zkclient, json=json)

    def setter(path, val, zstat):
        zkclient.set(path, val, version=zstat.version)

    try:
        for curr in txutil.cas_loop(zkclient.get, setter, args=(path, ),
                                    conflicterror=BadVersionError):
            yield curr
    finally:
{'fraction_non_alphanumeric': 0.08359872611464968, 'fraction_numerical': 0.0, 'mean_word_length': 2.891640866873065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3050460', 'n_tokens_mistral': 408, 'n_tokens_neox': 393, 'n_words': 97}