'Internal version of flush() with no locking.'

def _flush(self):

    records_to_be_flushed = []
    try:
        while True:
            group = log_service_pb.UserAppLogGroup()
            bytes_left = self._MAX_FLUSH_SIZE
            while self._buffer:
                record = self._get_record()
                if record.IsBlank():
                    continue
                message = self._clean(record.message)
                message = self._truncate(message, self._MAX_LINE_SIZE)
                if (len(message) > bytes_left):
                    self._rollback_record(record)
                    break
                records_to_be_flushed.append(record)
                line = group.add_log_line()
                line.set_timestamp_usec(record.created)
                line.set_level(record.level)
                if (record.source_location is not None):
                    line.mutable_source_location().set_file(record.source_location[0])
                    line.mutable_source_location().set_line(record.source_location[1])
                    line.mutable_source_location().set_function_name(record.source_location[2])
                line.set_message(message)
                bytes_left -= (1 + group.lengthString(line.ByteSize()))
            request = log_service_pb.FlushRequest()
            request.set_logs(group.Encode())
            response = api_base_pb.VoidProto()
            apiproxy_stub_map.MakeSyncCall('logservice', 'Flush', request, response)
            if (not self._buffer):
                break
    except apiproxy_errors.CancelledError:
        records_to_be_flushed.reverse()
        self._buffer.extendleft(records_to_be_flushed)
    except Exception as e:
        records_to_be_flushed.reverse()
        self._buffer.extendleft(records_to_be_flushed)
        line = ('-' * 80)
        msg = 'ERROR:    Could    not    flush    to    log_service    (%s)\n%s\n%s\n%s\n'
        _sys_stderr.write((msg % (e, line, self._contents(), line)))
        self._clear()
        raise
    else:
        self._clear()
