def CancelBatchJob(client, batch_job, max_poll_attempts=MAX_POLL_ATTEMPTS):
  batch_job_service = client.GetService('BatchJobService', 'v201509')
  batch_job['status'] = 'CANCELING'

  operation = {
      'operator': 'SET',
      'operand': batch_job
  }

  batch_job_service.mutate([operation])

  # Verify that the Batch Job cancels.
  poll_attempt = 0

  while (poll_attempt in range(max_poll_attempts) and
         batch_job['status'] != 'CANCELED'):
    sleep_interval = (30 * (2 ** poll_attempt) +
                      (random.randint(0, 10000) / 1000))
    print ('Batch Job not finished canceling, sleeping for %s seconds.'
           % sleep_interval)
    time.sleep(sleep_interval)
    batch_job = GetBatchJob(client, batch_job['id'])
    poll_attempt += 1

  if batch_job['status'] == 'CANCELED':
    print ('Batch Job with ID "%d" has been successfully canceled.' %
           batch_job['id'])
  else:
    print ('Batch Job with ID "%d" failed to cancel after polling %d times.'
           % (batch_job['id'], max_poll_attempts))
Cancels the given BatchJob.
dataset/ETHPy150Open googleads/googleads-python-lib/examples/adwords/v201509/campaign_management/add_keywords_using_incremental_batch_job.py/CancelBatchJob