Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8080#discussion_r36710452
  
    --- Diff: python/pyspark/streaming/context.py ---
    @@ -170,6 +173,48 @@ def getOrCreate(cls, checkpointPath, setupFunc):
             cls._transformerSerializer.ctx = sc
             return StreamingContext(sc, None, jssc)
     
    +    @classmethod
    +    def getActive(cls):
    +        """
    +        Return either the currently active StreamingContext (i.e., if 
there is a context started
    +        but not stopped) or None.
    +        """
    +        activePythonContext = cls._activeContext
    +        if activePythonContext is not None:
    +            # Verify that the current running Java StreamingContext is 
active and is the same one
    +            # backing the supposedly active Python context
    +            activePythonContextJavaId = 
activePythonContext._jssc.ssc().hashCode()
    +            activeJvmContextOption = 
activePythonContext._jvm.StreamingContext.getActive()
    +            if activeJvmContextOption.isEmpty() or \
    +                    activeJvmContextOption.get().hashCode() != 
activePythonContextJavaId:
    +                cls._activeContext = None
    +        return cls._activeContext
    +
    +    @classmethod
    +    def getActiveOrCreate(cls, checkpointPath, setupFunc):
    --- End diff --
    
    The problem is that then this order parameters is opposite of `getOrCreate` 
which in my own experience is creating a lot confusion when one switches 
between `getOrCreate` and `getActiveOrCreate`. That's why I explicitly kept the 
ordering same, as it is more annoying for developers to get the parameters 
order wrong (more so in Python than Java/Scala) than explicitly provide a 
checkpoint path or None. What do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to