<commit_before>import asyncio

from enum import Enum, unique

from plenum.common.log import getlogger

logger = getlogger()


class StatsPublisher:
    """
    Class to send data to TCP port which runs stats collecting service
    """

    def __init__(self, ip, port):
        self.ip = ip
        self.port = port
        self.reader = None
        self.writer = None

    async def sendMessage(self, message):
        loop = asyncio.get_event_loop()
        try:
            if self.writer is None:
                self.reader, self.writer = await asyncio.streams\
                    .open_connection(self.ip, self.port, loop=loop)
            self.writer.write((message + '\n').encode('utf-8'))
            await self.writer.drain()
        except (ConnectionRefusedError, ConnectionResetError) as ex:
            logger.debug("connection refused for {}:{} while sending message".
                         format(self.ip, self.port))
            self.writer = None

    def send(self, message):
        async def run():
            await self.sendMessage(message=message)
            # TODO: Can this sleep be removed?
            await asyncio.sleep(0.01)<commit_msg>catching an exception in stats publisher to let the node start, root cause of the exception need to be found, bug made in PT<commit_after>import asyncio

from enum import Enum, unique

from plenum.common.log import getlogger

logger = getlogger()


class StatsPublisher:
    """
    Class to send data to TCP port which runs stats collecting service
    """

    def __init__(self, ip, port):
        self.ip = ip
        self.port = port
        self.reader = None
        self.writer = None

    async def sendMessage(self, message):
        loop = asyncio.get_event_loop()
        try:
            if self.writer is None:
                self.reader, self.writer = await asyncio.streams\
                    .open_connection(self.ip, self.port, loop=loop)
            self.writer.write((message + '\n').encode('utf-8'))
            await self.writer.drain()
        except (ConnectionRefusedError, ConnectionResetError) as ex:
            logger.debug("connection refused for {}:{} while sending message".
                         format(self.ip, self.port))
            self.writer = None
        except AssertionError as ex:
            # TODO: THis is temporary for getting around `self.writer.drain`,
            # the root cause needs to be found out. Here is the bug,
            # https://www.pivotaltracker.com/story/show/132555801
            logger.warn("Error while sending message: {}".format(ex))
            self.writer = None

    def send(self, message):
        async def run():
            await self.sendMessage(message=message)
            # TODO: Can this sleep be removed?
            await asyncio.sleep(0.01)
{'fraction_non_alphanumeric': 0.09366096866096867, 'fraction_numerical': 0.006054131054131054, 'mean_word_length': 2.069945355191257, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '4149408', 'n_tokens_mistral': 761, 'n_tokens_neox': 738, 'n_words': 238}