Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/8080#discussion_r36708680
--- 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 --
Maybe it's better to exchange the locations of `checkpointPath` and
`setupFunc`, so that you can use `checkpointPath = None` here.
---
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]