<commit_before>import logging
from threading import RLock

import zmq

from ipc_channel import IpcChannel
from ipc_message import IpcMessage, IpcMessageException


class IpcClient(object):

    ENDPOINT_TEMPLATE = "tcp://{IP}:{PORT}"

    def __init__(self, ip_address, port):
        self.logger = logging.getLogger(self.__class__.__name__)

        self._ip_address = ip_address
        self._port = port

        self.ctrl_endpoint = self.ENDPOINT_TEMPLATE.format(
            IP=ip_address, PORT=port)
        self.logger.debug("Connecting to client at %s", self.ctrl_endpoint)
        self.ctrl_channel = IpcChannel(IpcChannel.CHANNEL_TYPE_DEALER)
        self.ctrl_channel.connect(self.ctrl_endpoint)

        self._lock = RLock()

    def _send_message(self, msg, timeout):
        self.logger.debug("Sending control message:\n%s", msg.encode())
        with self._lock:
            self.ctrl_channel.send(msg.encode())
            pollevts = self.ctrl_channel.poll(timeout)

        if pollevts == zmq.POLLIN:
            reply = IpcMessage(from_str=self.ctrl_channel.recv())
            if reply.is_valid() and reply.get_msg_type() == IpcMessage.ACK:
                self.logger.debug("Request successful")
                return True, reply.attrs
            else:
                self.logger.debug("Request unsuccessful")
                return False, reply.attrs
        else:
            self.logger.warning("Received no response")
            return False, None

    @staticmethod
    def _raise_reply_error(msg, reply):
        if reply is not None:
            raise IpcMessageException(
                "Request\n%s\nunsuccessful."
                " Got invalid response: %s" % (msg, reply))
        else:
            raise IpcMessageException(
                "Request\n%s\nunsuccessful."<commit_msg>Minor updates to IpcClient to ensure imports work successfully when used from an adapter class. Also include the reply message from a client when logging a successful reply.<commit_after>import logging
from threading import RLock

import zmq

from odin_data.ipc_channel import IpcChannel
from odin_data.ipc_message import IpcMessage, IpcMessageException


class IpcClient(object):

    ENDPOINT_TEMPLATE = "tcp://{IP}:{PORT}"

    def __init__(self, ip_address, port):
        self.logger = logging.getLogger(self.__class__.__name__)

        self._ip_address = ip_address
        self._port = port

        self.ctrl_endpoint = self.ENDPOINT_TEMPLATE.format(
            IP=ip_address, PORT=port)
        self.logger.debug("Connecting to client at %s", self.ctrl_endpoint)
        self.ctrl_channel = IpcChannel(IpcChannel.CHANNEL_TYPE_DEALER)
        self.ctrl_channel.connect(self.ctrl_endpoint)

        self._lock = RLock()

    def _send_message(self, msg, timeout):
        self.logger.debug("Sending control message:\n%s", msg.encode())
        with self._lock:
            self.ctrl_channel.send(msg.encode())
            pollevts = self.ctrl_channel.poll(timeout)

        if pollevts == zmq.POLLIN:
            reply = IpcMessage(from_str=self.ctrl_channel.recv())
            if reply.is_valid() and reply.get_msg_type() == IpcMessage.ACK:
                self.logger.debug("Request successful: %s", reply)
                return True, reply.attrs
            else:
                self.logger.debug("Request unsuccessful")
                return False, reply.attrs
        else:
            self.logger.warning("Received no response")
            return False, None

    @staticmethod
    def _raise_reply_error(msg, reply):
        if reply is not None:
            raise IpcMessageException(
                "Request\n%s\nunsuccessful."
                " Got invalid response: %s" % (msg, reply))
        else:
            raise IpcMessageException(
                "Request\n%s\nunsuccessful."
{'fraction_non_alphanumeric': 0.09328455709432976, 'fraction_numerical': 0.0, 'mean_word_length': 2.393617021276596, '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': '6328215', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1072, 'n_words': 246}