class_docstr: A :class:`TaskContext` with extra contextual info and tooling for tasks in a barrier stage.
  Use :func:`BarrierTaskContext.get` to obtain the barrier context for a running barrier task.
  
  .. versionadded:: 2.4.0
  
  Notes
  -----
  This API is experimental
  
  Examples
  --------
  Set a barrier, and execute it with RDD.
  
  >>> from pyspark import BarrierTaskContext
  >>> def block_and_do_something(itr):
  ...     taskcontext = BarrierTaskContext.get()
  ...     # Do something.
  ...
  ...     # Wait until all tasks finished.
  ...     taskcontext.barrier()
  ...
  ...     return itr
  ...
  >>> rdd = spark.sparkContext.parallelize([1])
  >>> rdd.barrier().mapPartitions(block_and_do_something).collect()
  [1]
docstr: Return the currently active :class:`BarrierTaskContext`.
  This can be called inside of user functions to access contextual information about
  running tasks.
  
  Notes
  -----
  Must be called on the worker, not the driver. Returns ``None`` if not initialized.
  An Exception will raise if it is not in a barrier stage.
  
  This API is experimental
docstr_tok: ["Return","the","currently","active",":","class",":","`","BarrierTaskContext","`",".","This","can","be","called","inside","of","user","functions","to","access","contextual","information","about","running","tasks",".","Notes","--","--","-","Must","be","called","on","the","worker",",","not","the","driver",".","Returns","``","None","``","if","not","initialized",".","An","Exception","will","raise","if","it","is","not","in","a","barrier","stage",".","This","API","is","experimental"]
code: def get(cls: Type["BarrierTaskContext"]) -> "BarrierTaskContext":
      """
      Return the currently active :class:`BarrierTaskContext`.
      This can be called inside of user functions to access contextual information about
      running tasks.
  
      Notes
      -----
      Must be called on the worker, not the driver. Returns ``None`` if not initialized.
      An Exception will raise if it is not in a barrier stage.
  
      This API is experimental
      """
      if not isinstance(cls._taskContext, BarrierTaskContext):
          raise PySparkRuntimeError(
              error_class="NOT_IN_BARRIER_STAGE",
              message_parameters={},
          )
      return cls._taskContext
  
imports: from typing import ClassVar, Type, Dict, List, Optional, Union, cast
  from pyspark.java_gateway import local_connect_and_auth
  from pyspark.resource import ResourceInformation
  from pyspark.serializers import read_int, write_int, write_with_length, UTF8Deserializer
  from pyspark.errors import PySparkRuntimeError
label_desc: Use image node_id 2 for calling the BarrierTaskContext obj's underlying member method code with example usage: obj.get(cls) and returns: cls