@@ -192,7 +192,7 @@ class ErrorResponseWithMessage(
192
192
fun JupyterConnection.Socket.controlMessagesHandler (msg : Message , repl : ReplForJupyter ? ) {
193
193
when (msg.content) {
194
194
is InterruptRequest -> {
195
- log.warn( " Interruption is not yet supported! " )
195
+ connection.interruptExecution( )
196
196
send(makeReplyMessage(msg, MessageType .INTERRUPT_REPLY , content = msg.content))
197
197
}
198
198
is ShutdownRequest -> {
@@ -439,6 +439,12 @@ fun JupyterConnection.evalWithIO(repl: ReplForJupyter, srcMessage: Message, body
439
439
val forkedError = getCapturingStream(err, JupyterOutType .STDERR , false )
440
440
val userError = getCapturingStream(null , JupyterOutType .STDERR , true )
441
441
442
+ fun flushStreams () {
443
+ forkedOut.flush()
444
+ forkedError.flush()
445
+ userError.flush()
446
+ }
447
+
442
448
val printForkedOut = PrintStream (forkedOut, false , " UTF-8" )
443
449
val printForkedErr = PrintStream (forkedError, false , " UTF-8" )
444
450
val printUserError = PrintStream (userError, false , " UTF-8" )
@@ -453,26 +459,30 @@ fun JupyterConnection.evalWithIO(repl: ReplForJupyter, srcMessage: Message, body
453
459
System .setIn(if (allowStdIn) stdinIn else DisabledStdinInputStream )
454
460
try {
455
461
return try {
456
- val exec = body()
457
- if (exec == null ) {
458
- AbortResponseWithMessage (" NO REPL!" )
459
- } else {
460
- forkedOut.flush()
461
- forkedError.flush()
462
- userError.flush()
463
-
464
- try {
465
- val result = exec.resultValue?.toDisplayResult(repl.notebook)
466
- OkResponseWithMessage (result, exec.metadata)
467
- } catch (e: Exception ) {
468
- AbortResponseWithMessage (" error: Unable to convert result to a string: $e " )
462
+ val (exec, execException, executionInterrupted) = runExecution(body)
463
+ when {
464
+ executionInterrupted -> {
465
+ flushStreams()
466
+ AbortResponseWithMessage (" The execution was interrupted" )
467
+ }
468
+ execException != null -> {
469
+ throw execException
470
+ }
471
+ exec == null -> {
472
+ AbortResponseWithMessage (" NO REPL!" )
473
+ }
474
+ else -> {
475
+ flushStreams()
476
+ try {
477
+ val result = exec.resultValue?.toDisplayResult(repl.notebook)
478
+ OkResponseWithMessage (result, exec.metadata)
479
+ } catch (e: Exception ) {
480
+ AbortResponseWithMessage (" error: Unable to convert result to a string: $e " )
481
+ }
469
482
}
470
483
}
471
484
} catch (ex: ReplException ) {
472
- forkedOut.flush()
473
- forkedError.flush()
474
- userError.flush()
475
-
485
+ flushStreams()
476
486
ErrorResponseWithMessage (
477
487
ex.render(),
478
488
ex.javaClass.canonicalName,
@@ -482,9 +492,7 @@ fun JupyterConnection.evalWithIO(repl: ReplForJupyter, srcMessage: Message, body
482
492
)
483
493
}
484
494
} finally {
485
- forkedOut.close()
486
- forkedError.close()
487
- userError.close()
495
+ flushStreams()
488
496
System .setIn(`in `)
489
497
System .setErr(err)
490
498
System .setOut(out )
0 commit comments