@@ -39,7 +39,7 @@ object Worksheet {
39
39
case statement : DefTree if statement.symbol.is(Synthetic ) =>
40
40
()
41
41
42
- case statement if executed.add(bounds(statement.pos)) =>
42
+ case statement if evaluator.isAlive() && executed.add(bounds(statement.pos)) =>
43
43
try {
44
44
cancelChecker.checkCanceled()
45
45
val (line, result) = execute(evaluator, statement, tree.source)
@@ -100,7 +100,7 @@ private object Evaluator {
100
100
def get (cancelChecker : CancelChecker )(implicit ctx : Context ): Option [Evaluator ] = {
101
101
val classpath = ctx.settings.classpath.value
102
102
previousEvaluator match {
103
- case Some (cp, evaluator) if cp == classpath =>
103
+ case Some (cp, evaluator) if evaluator.isAlive() && cp == classpath =>
104
104
evaluator.reset(cancelChecker)
105
105
Some (evaluator)
106
106
case _ =>
@@ -146,6 +146,9 @@ private class Evaluator private (javaExec: String,
146
146
// Wait for the REPL to be ready
147
147
processOutput.next()
148
148
149
+ /** Is the process that runs the REPL still alive? */
150
+ def isAlive (): Boolean = process.isAlive()
151
+
149
152
/**
150
153
* Submit `command` to the REPL, wait for the result.
151
154
*
@@ -185,7 +188,7 @@ private class CancellationThread(private[this] var cancelChecker: CancelChecker,
185
188
186
189
override def run (): Unit = {
187
190
try {
188
- while (! Thread .interrupted()) {
191
+ while (evaluator.isAlive() && ! Thread .interrupted()) {
189
192
cancelChecker.checkCanceled()
190
193
Thread .sleep(checkCancelledDelayMs)
191
194
}
0 commit comments