(conf={}, osenv={}, files=[], pyFiles=[], app_name=None)
return sc
Wrap pyspark.SparkContext.  If SparkContext has already been initialized,
    return the initialized Context

    There are two ways to call this function.  The simplest:

        sc = get_spark_context(app_name='myapp')

    The more complex:

        conf - (dict, required) a dictionary of key-value configuration
             - or, a pre-configured SparkConf instance
        osenv - (dict, optional) the environment variables to set on executors
        files - (list of str, optional) files to send to executors
        pyFiles - (list of str, optional) python files to send to executors

    If you wish to combine `app_name` with other kwargs, here's what happens:
        - the `osenv` is updated with env from app configuration if it exists
        - `conf`, if a dict, is treated like osenv and otherwise uses the app
        configuration data
        - files and pyFiles are extended to include app configuration


    An example configuration:
        conf = {
            "spark.app.name": "myapp",
            "spark.master": "local[30]",
            "spark.local.dir": "/tmp" }
Wrap pyspark.SparkContext.  If SparkContext has already been initialized,
    return the initialized Context
Wrap pyspark . SparkContext . If SparkContext has already been initialized return the initialized Context
def get_spark_context(conf={}, osenv={}, files=[], pyFiles=[], app_name=None):
    """Wrap pyspark.SparkContext.  If SparkContext has already been initialized,
    return the initialized Context

    There are two ways to call this function.  The simplest:

        sc = get_spark_context(app_name='myapp')

    The more complex:

        conf - (dict, required) a dictionary of key-value configuration
             - or, a pre-configured SparkConf instance
        osenv - (dict, optional) the environment variables to set on executors
        files - (list of str, optional) files to send to executors
        pyFiles - (list of str, optional) python files to send to executors

    If you wish to combine `app_name` with other kwargs, here's what happens:
        - the `osenv` is updated with env from app configuration if it exists
        - `conf`, if a dict, is treated like osenv and otherwise uses the app
        configuration data
        - files and pyFiles are extended to include app configuration


    An example configuration:
        conf = {
            "spark.app.name": "myapp",
            "spark.master": "local[30]",
            "spark.local.dir": "/tmp" }

    """
    if app_name:
        _conf, _osenv, _files, _pyFiles = get_spark_conf(app_name)
        # some stupid merge rules to support `app_name` and the other kwargs
        if isinstance(conf, dict):
            conf = dict(conf)
            conf.update(_conf)
        else:
            conf = _conf
        osenv = dict(osenv)
        osenv.update(_osenv)
        files = set(files)
        files.update(_files)
        files = list(files)
        pyFiles = set(pyFiles)
        pyFiles.update(_pyFiles)
        pyFiles = list(pyFiles)

    if not isinstance(conf, dict):
        assert isinstance(conf, SparkConf)
        conf = dict(conf.getAll())
    _spark_conf = SparkConf()
    for k, v in conf.items():
        _spark_conf.set(k, v)
    conf = _spark_conf

    if osenv:
        conf.setExecutorEnv(pairs=osenv.items())
    try:
        sc = SparkContext(conf=conf)
    except ValueError:
        log.warn("Another Spark Context is already active.  Using that one")
        return SparkContext._active_spark_context
    for method, lst in [(sc.addPyFile, pyFiles), (sc.addFile, files)]:
        for path in lst:
            if not path:
                continue
            method(path)
    atexit.register(sc.stop)
    return sc
def get_spark_context ( conf = { } , osenv = { } , files = [ ] , pyFiles = [ ] , app_name = None ) : if app_name : _conf , _osenv , _files , _pyFiles = get_spark_conf ( app_name ) # some stupid merge rules to support `app_name` and the other kwargs if isinstance ( conf , dict ) : conf = dict ( conf ) conf . update ( _conf ) else : conf = _conf osenv = dict ( osenv ) osenv . update ( _osenv ) files = set ( files ) files . update ( _files ) files = list ( files ) pyFiles = set ( pyFiles ) pyFiles . update ( _pyFiles ) pyFiles = list ( pyFiles ) if not isinstance ( conf , dict ) : assert isinstance ( conf , SparkConf ) conf = dict ( conf . getAll ( ) ) _spark_conf = SparkConf ( ) for k , v in conf . items ( ) : _spark_conf . set ( k , v ) conf = _spark_conf if osenv : conf . setExecutorEnv ( pairs = osenv . items ( ) ) try : sc = SparkContext ( conf = conf ) except ValueError : log . warn ( "Another Spark Context is already active.  Using that one" ) return SparkContext . _active_spark_context for method , lst in [ ( sc . addPyFile , pyFiles ) , ( sc . addFile , files ) ] : for path in lst : if not path : continue method ( path ) atexit . register ( sc . stop ) return sc