@@ -34,7 +34,7 @@ class StreamingContext(object):
3434
3535 def __init__ (self , master = None , appName = None , sparkHome = None , pyFiles = None ,
3636 environment = None , batchSize = 1024 , serializer = PickleSerializer (), conf = None ,
37- gateway = None , duration = None ):
37+ gateway = None , sparkContext = None , duration = None ):
3838 """
3939 Create a new StreamingContext. At least the master and app name and duration
4040 should be set, either through the named parameters here or through C{conf}.
@@ -55,14 +55,18 @@ def __init__(self, master=None, appName=None, sparkHome=None, pyFiles=None,
5555 @param conf: A L{SparkConf} object setting Spark properties.
5656 @param gateway: Use an existing gateway and JVM, otherwise a new JVM
5757 will be instatiated.
58- @param duration: A L{Duration} Duration for SparkStreaming
58+ @param sparkContext: L{SparkContext} object.
59+ @param duration: A L{Duration} object for SparkStreaming.
5960
6061 """
6162
62- # Create the Python Sparkcontext
63- self ._sc = SparkContext (master = master , appName = appName , sparkHome = sparkHome ,
64- pyFiles = pyFiles , environment = environment , batchSize = batchSize ,
65- serializer = serializer , conf = conf , gateway = gateway )
63+ if sparkContext is None :
64+ # Create the Python Sparkcontext
65+ self ._sc = SparkContext (master = master , appName = appName , sparkHome = sparkHome ,
66+ pyFiles = pyFiles , environment = environment , batchSize = batchSize ,
67+ serializer = serializer , conf = conf , gateway = gateway )
68+ else :
69+ self ._sc = sparkContext
6670
6771 # Start py4j callback server.
6872 # Callback sever is need only by SparkStreming; therefore the callback sever
0 commit comments