<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def send_message(self, stream, msg):
 """Send an arbitrary message to a particular client. Parameters stream : :class:`tornado.iostream.IOStream` object The stream to send the message to. msg : Message object The message to send. Notes ----- This method can only be called in the IOLoop thread. Failed sends disconnect the client connection and calls the device on_client_disconnect() method. They do not raise exceptions, but they are logged. Sends also fail if more than self.MAX_WRITE_BUFFER_SIZE bytes are queued for sending, implying that client is falling behind. """

        assert get_thread_ident() == self.ioloop_thread_id
        try:
            if stream.KATCPServer_closing:
                raise RuntimeError('Stream is closing so we cannot '
                                   'accept any more writes')
            return stream.write(str(msg) + '\n')
        except Exception:
            addr = self.get_address(stream)
            self._logger.warn('Could not send message {0!r} to {1}'
                              .format(str(msg), addr), exc_info=True)
            stream.close(exc_info=True)