Github user zsxwing commented on a diff in the pull request:
https://github.com/apache/spark/pull/8080#discussion_r36707649
--- 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:
--- End diff --
I think it's better to throw an exception when
`activeJvmContextOption.get().hashCode() != activePythonContextJavaId` because
it will be confusing that `getActive` returns None but `getActiveOrCreate`
still complains there is already an active context in Scala codes.
---
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]