vinooganesh commented on a change in pull request #28128:
URL: https://github.com/apache/spark/pull/28128#discussion_r421037627



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/SparkSession.scala
##########
@@ -691,21 +752,56 @@ class SparkSession private(
   }
   // scalastyle:on
 
+  /**
+   * Lifecycle method that cleans up state of spark session, and mark session
+   * "ended" forever. This differs from `stop()` or `stopContext()` as it keeps
+   * the underlying `SparkContext` alive, while only getting
+   */
+
+  def terminate(): Unit = {
+    // Session is still active
+    if (!_terminated.get()) {
+      sparkContext.removeSparkListener(this._sessionListener)
+      SparkSession.removeTerminatedSession(_sessionId)
+      _terminated.set(true)
+    }
+    else {
+      throw new IllegalStateException(
+        s"""Cannot call methods on a terminated SparkSession. Call

Review comment:
       good flag - fixing




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to