pyspark.SparkContext.getOrCreate

classmethod SparkContext.getOrCreate(conf: Optional[pyspark.conf.SparkConf] = None) → pyspark.context.SparkContext[source]

Get or instantiate a SparkContext and register it as a singleton object.

New in version 1.4.0.

Parameters
confSparkConf, optional

SparkConf that will be used for initialization of the SparkContext.

Returns
SparkContext

current SparkContext, or a new one if it wasn’t created before the function call.

Examples

>>> SparkContext.getOrCreate()
<SparkContext ...>