Skip to content

Commit c6bf281

Browse files
committed
Don't kill process when embedded
1 parent d42c87a commit c6bf281

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/kotlin/org/jetbrains/kotlinx/jupyter/protocol.kt

+9-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,15 @@ fun JupyterConnection.Socket.controlMessagesHandler(msg: Message, repl: ReplForJ
195195
is ShutdownRequest -> {
196196
repl?.evalOnShutdown()
197197
send(makeReplyMessage(msg, MessageType.SHUTDOWN_REPLY, content = msg.content))
198-
exitProcess(0)
198+
// exitProcess would kill the entire process that embedded the kernel
199+
// Instead the controlThread will be interrupted,
200+
// which will then interrupt the mainThread and make kernelServer return
201+
if ((repl as? ReplForJupyterImpl)?.isEmbedded() == true) {
202+
log.info("Interrupting controlThread to trigger kernel shutdown")
203+
throw InterruptedException()
204+
} else {
205+
exitProcess(0)
206+
}
199207
}
200208
}
201209
}

src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl.kt

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class ReplForJupyterImpl(
148148
private val embedded: Boolean = false,
149149
) : ReplForJupyter, ReplOptions, BaseKernelHost, KotlinKernelHostProvider {
150150

151+
fun isEmbedded() = embedded
152+
151153
constructor(
152154
config: KernelConfig,
153155
runtimeProperties: ReplRuntimeProperties,

0 commit comments

Comments
 (0)