<commit_before>import asyncio
import aioredis


STOPWORD = 'STOP'


@asyncio.coroutine
def pubsub():
    pool = yield from aioredis.create_pool(
        ('localhost', 6379),
        minsize=5, maxsize=10)

    @asyncio.coroutine
    def reader(channel):
        while (yield from channel.wait_message()):
            msg = yield from channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

            if msg == STOPWORD:
                return

    with (yield from pool) as redis:
        channel, = yield from redis.subscribe('channel:1')
        yield from reader(channel)  # wait for reader to complete
        yield from redis.unsubscribe('channel:1')

    # Explicit redis usage
    redis = yield from pool.acquire()
    try:
        channel, = yield from redis.subscribe('channel:1')
        yield from reader(channel)  # wait for reader to complete
        yield from redis.unsubscribe('channel:1')
    finally:
        pool.release(redis)

    yield from pool.clear()    # closing all open connections


def main():
    loop = asyncio.get_event_loop()
    tsk = asyncio.async(pubsub(), loop=loop)

    @asyncio.coroutine
    def publish():
        pub = yield from aioredis.create_redis(
            ('localhost', 6379))
        while not tsk.done():
            # wait for clients to subscribe
            while True:
                subs = yield from pub.pubsub_numsub('channel:1')
                if subs[b'channel:1'] == 1:
                    break
                yield from asyncio.sleep(0, loop=loop)
            # publish some messages
            for msg in ['one', 'two', 'three']:
                yield from pub.publish('channel:1', msg)
            # send stop word
            yield from pub.publish('channel:1', STOPWORD)
        pub.close()
        yield from pub.wait_closed()

    loop.run_until_complete(asyncio.gather(publish(), tsk, loop=loop))


if __name__ == '__main__':
    main()<commit_msg>example fix<commit_after>import asyncio
import aioredis


STOPWORD = 'STOP'


@asyncio.coroutine
def pubsub():
    pool = yield from aioredis.create_pool(
        ('localhost', 6379),
        minsize=5, maxsize=10)

    @asyncio.coroutine
    def reader(channel):
        while (yield from channel.wait_message()):
            msg = yield from channel.get(encoding='utf-8')
            # ... process message ...
            print("message in {}: {}".format(channel.name, msg))

            if msg == STOPWORD:
                return

    with (yield from pool) as redis:
        channel, = yield from redis.subscribe('channel:1')
        yield from reader(channel)  # wait for reader to complete
        yield from redis.unsubscribe('channel:1')

    # Explicit redis usage
    redis = yield from pool.acquire()
    try:
        channel, = yield from redis.subscribe('channel:1')
        yield from reader(channel)  # wait for reader to complete
        yield from redis.unsubscribe('channel:1')
    finally:
        pool.release(redis)

    yield from pool.clear()    # closing all open connections


def main():
    loop = asyncio.get_event_loop()
    tsk = asyncio.async(pubsub(), loop=loop)

    @asyncio.coroutine
    def publish():
        pub = yield from aioredis.create_redis(
            ('localhost', 6379))
        while not tsk.done():
            # wait for clients to subscribe
            while True:
                subs = yield from pub.pubsub_numsub('channel:1')
                if subs[b'channel:1'] == 1:
                    break
                yield from asyncio.sleep(0, loop=loop)
            # publish some messages
            for msg in ['one', 'two', 'three']:
                yield from pub.publish('channel:1', msg)
            # send stop word
            yield from pub.publish('channel:1', STOPWORD)
        pub.close()
        yield from pub.wait_closed()

    loop.run_until_complete(asyncio.gather(publish(), tsk, loop=loop))


if __name__ == '__main__':
    import os
    if 'redis_version:2.6' not in os.environ.get('REDIS_VERSION', ''):
        main()
{'fraction_non_alphanumeric': 0.11276543812545765, 'fraction_numerical': 0.011227727605565048, 'mean_word_length': 2.135424636572303, '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': '6401990', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1170, 'n_words': 327}