attilapiros commented on a change in pull request #33936:
URL: https://github.com/apache/spark/pull/33936#discussion_r704221037



##########
File path: repl/src/main/scala/org/apache/spark/repl/InactivityTimeout.scala
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.repl
+
+import java.util.{Timer, TimerTask}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.repl.Main.{conf, sparkContext}
+
+object InactivityTimeout extends Logging {
+  private[repl] var inactivityTimeoutMs = 
conf.getTimeAsMs("spark.repl.inactivityTimeout", "0s")
+  private[repl] var isTest: Boolean = false
+
+  private var inactivityTimer: Option[Timer] = None
+
+  private class InactivityTimerTask extends TimerTask {
+
+    override def run(): Unit = {
+      logError(s"Inactivity timeout of $inactivityTimeoutMs ms reached - 
closing shell")
+      if (!isTest) {
+        Option(sparkContext).foreach(_.stop)
+        System.exit(1)
+      }
+    }
+
+  }
+
+  def stopInactivityTimer(): Unit = {
+    inactivityTimer.foreach(_.cancel())
+  }
+
+  def startInactivityTimer(): Unit = {
+    if (inactivityTimeoutMs > 0) {
+      inactivityTimer.foreach(_.cancel())
+      inactivityTimer = Option(new Timer(true))

Review comment:
       We can name this Timer so:
   
   ```suggestion
         inactivityTimer = Some(new Timer("SparkShellInactivityTimer", isDaemon 
= true))
   ```

##########
File path: repl/src/main/scala/org/apache/spark/repl/InactivityTimeout.scala
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.repl
+
+import java.util.{Timer, TimerTask}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.repl.Main.{conf, sparkContext}

Review comment:
       Please import just `Main` and use `Main.conf` and `Main.sparkContext` 
where it is needed.

##########
File path: repl/src/main/scala/org/apache/spark/repl/InactivityTimeout.scala
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.repl
+
+import java.util.{Timer, TimerTask}

Review comment:
       Nit: "Avoid using wildcard imports, unless you are importing more than 6 
entities, or implicit methods"
   
   As suggested at https://github.com/databricks/scala-style-guide#imports

##########
File path: repl/src/main/scala-2.12/org/apache/spark/repl/SparkILoop.scala
##########
@@ -34,6 +34,8 @@ import scala.tools.nsc.interpreter.StdReplTags.tagOfIMain
 import scala.tools.nsc.util.stringFromStream
 import scala.util.Properties.{javaVersion, javaVmName, versionString}
 
+import org.apache.spark.repl.InactivityTimeout.{startInactivityTimer, 
stopInactivityTimer}

Review comment:
       Please import just InactivityTimeout and use 
InactivityTimeout.startInactivityTimer and 
InactivityTimeout.stopInactivityTimer where it is needed.
   
   

##########
File path: repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala
##########
@@ -55,7 +55,14 @@ class ReplSuite extends SparkFunSuite with BeforeAndAfterAll 
{
     Main.sparkSession = null // causes recreation of SparkContext for each 
test.
     Main.conf.set("spark.master", master)
 
-    val in = new BufferedReader(new StringReader(input + "\n"))
+    class SlowBufferedReader(in: Reader, readLineDelay: Long) extends 
BufferedReader(in) {
+      override def readLine(): String = {
+        if (readLineDelay > 0) Thread.sleep(readLineDelay)

Review comment:
       "Put curly braces even around one-line conditional or loop statements" 
   As suggested in https://github.com/databricks/scala-style-guide#curly-braces

##########
File path: repl/src/main/scala-2.13/org/apache/spark/repl/SparkILoop.scala
##########
@@ -17,6 +17,8 @@
 
 package org.apache.spark.repl
 
+import org.apache.spark.repl.InactivityTimeout.{startInactivityTimer, 
stopInactivityTimer}

Review comment:
       Please import just `InactivityTimeout` and use 
`InactivityTimeout.startInactivityTimer` and 
`InactivityTimeout.stopInactivityTimer` where it is needed.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to