<commit_before>import asyncio
import aioetcd.client

@asyncio.coroutine
def print_leader():
    client = aioetcd.client.Client()
    result = yield from client.leader()
    print(result)

@asyncio.coroutine
def client_set(key, value):
    client = aioetcd.client.Client()
    result = yield from client.set(key, value)
    print(result)

@asyncio.coroutine
def client_get(key):
    client = aioetcd.client.Client()
    result = yield from client.get(key)
    print(result)

@asyncio.coroutine
def print_machines():
    client = aioetcd.client.Client()
    result = yield from client.machines()
    print(result)

@asyncio.coroutine
def watch_eternally():
    client = aioetcd.client.Client(read_timeout=2, allow_reconnect=True)
    result = yield from client.watch('hello')
    print(result)

@asyncio.coroutine
def watch_timeout():
    client = aioetcd.client.Client(read_timeout=2, allow_reconnect=True)
    result = yield from client.watch('hello', timeout=5)
    print(result)

@asyncio.coroutine
def main():
    loop = asyncio.get_event_loop()
    loop.create_task(print_leader())
    loop.create_task(print_machines())
    loop.create_task(client_set('hop', 42))
    loop.create_task(client_get('hop'))
    yield from watch_eternally()
    yield from watch_timeout()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
<commit_msg>use watch_forever in example client<commit_after>import asyncio
import aioetcd.client

@asyncio.coroutine
def print_leader():
    print('print_leader')
    client = aioetcd.client.Client()
    result = yield from client.leader()
    print(result)

@asyncio.coroutine
def client_set(key, value):
    print('client_set')
    client = aioetcd.client.Client()
    result = yield from client.set(key, value)
    print(result)

@asyncio.coroutine
def client_get(key):
    print('client_get')
    client = aioetcd.client.Client()
    result = yield from client.get(key)
    print(result)

@asyncio.coroutine
def print_machines():
    print('print_machine')
    client = aioetcd.client.Client()
    result = yield from client.machines()
    print(result)

@asyncio.coroutine
def watch_eternally(key):
    print('watch_eternally')
    client = aioetcd.client.Client(read_timeout=2, allow_reconnect=True)
    result = yield from client.watch(key)
    print(result)

@asyncio.coroutine
def watch_timeout(key):
    print('watch_timeout')
    client = aioetcd.client.Client(read_timeout=2, allow_reconnect=True)
    result = yield from client.watch(key, timeout=5)
    print(result)

@asyncio.coroutine
def watch_forever(key):
    print('watch_forever')
    client = aioetcd.client.Client(read_timeout=5, allow_reconnect=True)
    for watcher in client.watch_forever(key):
        resp = yield from watcher
        print(resp.value)
        if resp.value == '42':
            break

@asyncio.coroutine
def main():
    loop = asyncio.get_event_loop()
    print('---------------------')
    yield from print_leader()
    print('---------------------')
    yield from print_machines()
    print('---------------------')
    yield from client_set('hello', 43)
    print('---------------------')
    yield from client_get('hello')
    print('---------------------')
    # run :
    #    etcdctl set hello 0
    # a couple of time and then
    #    etcdctl set hello 42
    # as soon as it becomes boring
    yield from watch_forever('hello')
    print('---------------------')
    # run :
    #    etcdctl set hello 0
    # to unlock
    yield from watch_eternally("hello")
    print('---------------------')
    # run :
    #    etcdctl set hello 0
    # or wait 5 seconds to unlock
    yield from watch_timeout('hello')

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()


{'fraction_non_alphanumeric': 0.15056059797116925, 'fraction_numerical': 0.005072076882007475, 'mean_word_length': 3.1357615894039736, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5074421', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1210, 'n_words': 265}