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: Internal function to get or create global :class:`BarrierTaskContext`. We need to make sure
  :class:`BarrierTaskContext` is returned from here because it is needed in python worker
  reuse scenario, see SPARK-25921 for more details.
docstr_tok: ["Internal","function","to","get","or","create","global",":","class",":","`","BarrierTaskContext","`",".","We","need","to","make","sure",":","class",":","`","BarrierTaskContext","`","is","returned","from","here","because","it","is","needed","in","python","worker","reuse","scenario",",","see","SPARK-25921","for","more","details","."]
code: def _getOrCreate(
      cls: Type["BarrierTaskContext"],
  ) -> "BarrierTaskContext":
      """
      Internal function to get or create global :class:`BarrierTaskContext`. We need to make sure
      :class:`BarrierTaskContext` is returned from here because it is needed in python worker
      reuse scenario, see SPARK-25921 for more details.
      """
      if not isinstance(cls._taskContext, BarrierTaskContext):
          cls._taskContext = object.__new__(cls)
      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 1 for calling the BarrierTaskContext obj's underlying member method code with example usage: obj._getOrCreate(cls) and returns: cls