@@ -39,7 +39,7 @@ object Worksheet {
3939 case statement : DefTree if statement.symbol.is(Synthetic ) =>
4040 ()
4141
42- case statement if executed.add(bounds(statement.pos)) =>
42+ case statement if evaluator.isAlive() && executed.add(bounds(statement.pos)) =>
4343 try {
4444 cancelChecker.checkCanceled()
4545 val (line, result) = execute(evaluator, statement, tree.source)
@@ -100,7 +100,7 @@ private object Evaluator {
100100 def get (cancelChecker : CancelChecker )(implicit ctx : Context ): Option [Evaluator ] = {
101101 val classpath = ctx.settings.classpath.value
102102 previousEvaluator match {
103- case Some (cp, evaluator) if cp == classpath =>
103+ case Some (cp, evaluator) if evaluator.isAlive() && cp == classpath =>
104104 evaluator.reset(cancelChecker)
105105 Some (evaluator)
106106 case _ =>
@@ -146,6 +146,9 @@ private class Evaluator private (javaExec: String,
146146 // Wait for the REPL to be ready
147147 processOutput.next()
148148
149+ /** Is the process that runs the REPL still alive? */
150+ def isAlive (): Boolean = process.isAlive()
151+
149152 /**
150153 * Submit `command` to the REPL, wait for the result.
151154 *
@@ -185,7 +188,7 @@ private class CancellationThread(private[this] var cancelChecker: CancelChecker,
185188
186189 override def run (): Unit = {
187190 try {
188- while (! Thread .interrupted()) {
191+ while (evaluator.isAlive() && ! Thread .interrupted()) {
189192 cancelChecker.checkCanceled()
190193 Thread .sleep(checkCancelledDelayMs)
191194 }
0 commit comments