Skip to content

Commit 1ba208a

Browse files
author
Cheolsoo Park
committed
Code clean up using scala try, success, and failure
1 parent 368e4eb commit 1ba208a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

core/src/main/scala/org/apache/spark/scheduler/JobWaiter.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.spark.scheduler
1919

20-
import scala.util.Try
20+
import scala.util.{Failure, Success, Try}
2121

2222
import org.apache.spark.Logging
2323

@@ -38,8 +38,8 @@ private[spark] class JobWaiter[T](
3838
@volatile
3939
private var _originalHandler: SignalHandler = null
4040

41-
def attachSigintHandler(): SignalHandler = {
42-
Signal.handle(sigint, new SignalHandler with Logging {
41+
def attachSigintHandler(): Unit = {
42+
_originalHandler = Signal.handle(sigint, new SignalHandler with Logging {
4343
override def handle(signal: Signal): Unit = {
4444
logInfo("Cancelling running job.. This might take some time, so be patient. " +
4545
"Press Ctrl-C again to kill JVM.")
@@ -97,11 +97,14 @@ private[spark] class JobWaiter[T](
9797
}
9898

9999
def awaitResult(): JobResult = synchronized {
100-
Try(_originalHandler = attachSigintHandler())
100+
val attachTry = Try(attachSigintHandler())
101101
while (!_jobFinished) {
102102
this.wait()
103103
}
104-
Try(detachSigintHandler())
104+
attachTry match {
105+
case _: Success[_] => detachSigintHandler()
106+
case _: Failure[_] => // Ignore error. Signal handler is on a best effort basis.
107+
}
105108
return jobResult
106109
}
107110
}

0 commit comments

Comments
 (0)