def with_spark_context(application_name, conf=None):
"""Context manager for a spark context
Parameters
----------
application_name : string
conf : string, optional
Returns
-------
sc : SparkContext
Examples
--------
Used within a context manager
>>> with with_spark_context("MyApplication") as sc:
... # Your Code here
... pass
"""
if conf is None:
conf = default_configuration
assert isinstance(conf, SparkConfiguration)
sc = conf.spark_context(application_name)
try:
yield sc
finally:
sc.stop()
评论列表
文章目录