class_docstr: Interact with Amazon EMR Serverless.
  
  Provide thin wrapper around :py:class:`boto3.client("emr-serverless") <EMRServerless.Client>`.
  
  Additional arguments (such as ``aws_conn_id``) may be specified and
  are passed down to the underlying AwsBaseHook.
  
  .. seealso::
      - :class:`airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
class_docstr_tok: ["Interact","with","Amazon","EMR","Serverless",".","Provide","thin","wrapper","around",":","py",":","class",":","`","boto3.client","(","``","emr-serverless","''",")","<","EMRServerless.Client",">","`",".","Additional","arguments","(","such","as","``","aws_conn_id","``",")","may","be","specified","and","are","passed","down","to","the","underlying","AwsBaseHook",".","..","seealso",":",":","-",":","class",":","`","airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook","`"]
docstr: Cancel jobs in an intermediate state, and return the number of cancelled jobs.
  
  If wait_for_completion is True, then the method will wait until all jobs are
  cancelled before returning.
  
  Note: if new jobs are triggered while this operation is ongoing,
  it's going to time out and return an error.
docstr_tok: ["Cancel","jobs","in","an","intermediate","state",",","and","return","the","number","of","cancelled","jobs",".","If","wait_for_completion","is","True",",","then","the","method","will","wait","until","all","jobs","are","cancelled","before","returning",".","Note",":","if","new","jobs","are","triggered","while","this","operation","is","ongoing",",","it","'s","going","to","time","out","and","return","an","error","."]
code: def cancel_running_jobs(
      self,
      application_id: str,
      waiter_config: dict | None = None,
      wait_for_completion: bool = True,
  ) -> int:
      """
      Cancel jobs in an intermediate state, and return the number of cancelled jobs.
  
      If wait_for_completion is True, then the method will wait until all jobs are
      cancelled before returning.
  
      Note: if new jobs are triggered while this operation is ongoing,
      it's going to time out and return an error.
      """
      paginator = self.conn.get_paginator("list_job_runs")
      results_per_response = 50
      iterator = paginator.paginate(
          applicationId=application_id,
          states=list(self.JOB_INTERMEDIATE_STATES),
          PaginationConfig={
              "PageSize": results_per_response,
          },
      )
      count = 0
      for r in iterator:
          job_ids = [jr["id"] for jr in r["jobRuns"]]
          count += len(job_ids)
          if job_ids:
              self.log.info(
                  "Cancelling %s pending job(s) for the application %s so that it can be stopped",
                  len(job_ids),
                  application_id,
              )
              for job_id in job_ids:
                  self.conn.cancel_job_run(
                      applicationId=application_id, jobRunId=job_id
                  )
      if wait_for_completion:
          if count > 0:
              self.log.info(
                  "now waiting for the %s cancelled job(s) to terminate",
                  count,
              )
              self.get_waiter("no_job_running").wait(
                  applicationId=application_id,
                  states=list(
                      self.JOB_INTERMEDIATE_STATES.union({"CANCELLING"})
                  ),
                  WaiterConfig=waiter_config or {},
              )
  
      return count
  
imports: from __future__ import annotations
  import json
  import time
  import warnings
  from typing import Any
  from botocore.exceptions import ClientError
  from airflow.exceptions import AirflowException, AirflowNotFoundException
  from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
  from airflow.providers.amazon.aws.utils.waiter_with_logging import wait
label_desc: Use image node_id 2 for calling the EmrServerlessHook obj's underlying member method code with example usage: obj.cancel_running_jobs(application_id, waiter_config, wait_for_completion) and returns: count