def _ExecuteBatchRequest(self, requests):
        """Executes the given |requests| in batches.

        Documentation:
        * https://developers.google.com/api-client-library/python/guide/batch

        Args:
          requests: list of (request_id, request) pairs
        """
        def _BatchHttpRequestCallback(request_id, response, exception):
            if exception is not None:
                print 'Error: %s' % exception
            else:
                self._PrintJsonResponse(request_id, response)

        batch = None
        num_batch_requests = 0
        MAX_BATCH_SIZE = 1000  # documented at the URL above

        for request_id, request in requests:
            if batch is None:
                batch = http.BatchHttpRequest(
                    callback=_BatchHttpRequestCallback)
            batch.add(request, request_id=request_id)
            num_batch_requests += 1
            if num_batch_requests == MAX_BATCH_SIZE:
                batch.execute(http=self.__auth_http)
                batch = None
                num_batch_requests = 0

        # Execute the left-over requests in the batch if there are any.
        if batch is not None:
            batch.execute(http=self.__auth_http)
            batch = None
dataset/ETHPy150Open mbrukman/cloud-launcher/src/cloud_launcher.py/GceHandler._ExecuteBatchRequest/original