aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorShixiong Zhu <shixiong@databricks.com>2017-02-09 11:16:51 -0800
committerDavies Liu <davies.liu@gmail.com>2017-02-09 11:16:51 -0800
commit303f00a4bf6660dd83c8bd9e3a107bb3438a421b (patch)
treedf6209c244f94d4ea7782e1ace2b1099e8f50d58 /core/src
parent6287c94f08200d548df5cc0a401b73b84f9968c4 (diff)
downloadspark-303f00a4bf6660dd83c8bd9e3a107bb3438a421b.tar.gz
spark-303f00a4bf6660dd83c8bd9e3a107bb3438a421b.tar.bz2
spark-303f00a4bf6660dd83c8bd9e3a107bb3438a421b.zip
[SPARK-19481] [REPL] [MAVEN] Avoid to leak SparkContext in Signaling.cancelOnInterrupt
## What changes were proposed in this pull request? `Signaling.cancelOnInterrupt` leaks a SparkContext per call and it makes ReplSuite unstable. This PR adds `SparkContext.getActive` to allow `Signaling.cancelOnInterrupt` to get the active `SparkContext` to avoid the leak. ## How was this patch tested? Jenkins Author: Shixiong Zhu <shixiong@databricks.com> Closes #16825 from zsxwing/SPARK-19481.
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/scala/org/apache/spark/SparkContext.scala7
1 files changed, 7 insertions, 0 deletions
diff --git a/core/src/main/scala/org/apache/spark/SparkContext.scala b/core/src/main/scala/org/apache/spark/SparkContext.scala
index 40189a2256..eb13686f26 100644
--- a/core/src/main/scala/org/apache/spark/SparkContext.scala
+++ b/core/src/main/scala/org/apache/spark/SparkContext.scala
@@ -2489,6 +2489,13 @@ object SparkContext extends Logging {
}
}
+ /** Return the current active [[SparkContext]] if any. */
+ private[spark] def getActive: Option[SparkContext] = {
+ SPARK_CONTEXT_CONSTRUCTOR_LOCK.synchronized {
+ Option(activeContext.get())
+ }
+ }
+
/**
* Called at the beginning of the SparkContext constructor to ensure that no SparkContext is
* running. Throws an exception if a running context is detected and logs a warning if another