<commit_before>import asyncio
import sys

import nanomsg as nn
from nanomsg.asyncio import Socket


async def ping(url, barrier):
    with Socket(protocol=nn.NN_PUSH) as sock, sock.connect(url):
        await sock.send(b'Hello, World!')
        # Shutdown the endpoint after the other side ack'ed; otherwise
        # the message could be lost.
        await barrier.wait()


async def pong(url, barrier):
    with Socket(protocol=nn.NN_PULL) as sock, sock.bind(url):
        message = await sock.recv()
        print(bytes(message.as_memoryview()).decode('ascii'))
        await barrier.wait()


async def close_loop(barrier):
    await barrier.wait()
    asyncio.get_event_loop().stop()


class Barrier:

    def __init__(self, parties, *, loop=None):
        self.parties = parties
        self._cond = asyncio.Condition(loop=loop)

    async def wait(self):
        await self._cond.acquire()
        try:
            assert self.parties > 0
            self.parties -= 1
            if self.parties > 0:
                await self._cond.wait()
            else:
                self._cond.notify_all()
            assert self.parties == 0
        finally:
            self._cond.release()


def main():
    barrier = Barrier(3)

    url = 'inproc://test'
    print('Play asynchronous ping-pong on %s' % url)
    asyncio.ensure_future(ping(url, barrier))
    asyncio.ensure_future(pong(url, barrier))

    asyncio.ensure_future(close_loop(barrier))

    loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    finally:
        loop.close()
    return 0


if __name__ == '__main__':
    sys.exit(main())<commit_msg>Simplify nanomsg sample<commit_after>import asyncio
import sys

import nanomsg as nn
from nanomsg.asyncio import Socket


async def ping(url, ack):
    with Socket(protocol=nn.NN_PUSH) as sock, sock.connect(url):
        await sock.send(b'Hello, World!')
        # Shutdown the endpoint after the other side ack'ed; otherwise
        # the message could be lost.
        await ack.wait()


async def pong(url, ack):
    with Socket(protocol=nn.NN_PULL) as sock, sock.bind(url):
        message = await sock.recv()
        print(bytes(message.as_memoryview()).decode('ascii'))
        ack.set()


def main():
    url = 'inproc://test'
    print('Play asynchronous ping-pong on %s' % url)
    loop = asyncio.get_event_loop()
    ack = asyncio.Event()
    loop.run_until_complete(asyncio.wait([
        asyncio.ensure_future(ping(url, ack)),
        asyncio.ensure_future(pong(url, ack)),
    ]))
    loop.close()
    return 0


if __name__ == '__main__':
    sys.exit(main())
{'fraction_non_alphanumeric': 0.11775987725354814, 'fraction_numerical': 0.002685078634445723, 'mean_word_length': 2.6272600834492352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2123828', 'n_tokens_mistral': 860, 'n_tokens_neox': 832, 'n_words': 204}