Perform a batch write and handle the response

def _write(self, items):
        """ Perform a batch write and handle the response """
        response = self._batch_write_item(items)
        if 'consumed_capacity' in response:
            # Comes back as a list from BatchWriteItem
            self.consumed_capacity = \
                sum(response['consumed_capacity'], self.consumed_capacity)

        if response.get('UnprocessedItems'):
            unprocessed = response['UnprocessedItems'].get(self.tablename, [])

            # Some items have not been processed. Stow them for now &
            # re-attempt processing on ``__exit__``.
            LOG.info("%d items were unprocessed. Storing for later.",
                     len(unprocessed))
            self._unprocessed.extend(unprocessed)
            # Getting UnprocessedItems indicates that we are exceeding our
            # throughput. So sleep for a bit.
            self._attempt += 1
            self.connection.exponential_sleep(self._attempt)
        else:
            # No UnprocessedItems means our request rate is fine, so we can
            # reset the attempt number.
            self._attempt = 0

        return response