def flush()

in fluentmetrics/buffer.py [0:0]


    def flush(self, send_partial=True):
        '''Sends as much data as possible to CloudWatch. If send_partial is set to False,
        this only sends full pages. This way, it minimizes the API usage at the cost of
        delaying data.
        '''
        for namespace, buffer in self.buffers.items():
            full_pages = len(buffer) // PAGE_SIZE
            for i in range(full_pages):
                start = i * PAGE_SIZE
                end = (i + 1) * PAGE_SIZE
                page = buffer[start:end]

                # ship it
                FluentMetric._record_metric(self, page)

            start = full_pages * PAGE_SIZE
            end = len(buffer) % PAGE_SIZE
            if send_partial:
                # ship remaining items
                page = buffer[start:end]
                FluentMetric._record_metric(self, page)

                # clear buffer
                self.buffers[namespace] = []

            # This condition isn't needed for correctness, it could be an else, it just
            # reduces memory churn. You should get the same result either way.
            elif full_pages > 0:
                # clear shipped items from buffer
                self.buffers[namespace] = buffer[start:]

        return self