Skip to content

Commit

Permalink
KTNB-794: Restart Spring sever on shutdown request
Browse files Browse the repository at this point in the history
  • Loading branch information
ileasile committed Oct 18, 2024
1 parent 4dfb70c commit 860d874
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,29 @@ class KotlinJupyterKernelService(
clientType = clientType,
)

private var shouldRestart = true

private val kernelThread =
thread {
startKernel(
DefaultKernelLoggerFactory,
SpringProcessKernelRunMode,
kernelConfig,
DefaultResolutionInfoProviderFactory,
)
runKernelService()
}

private fun runKernelService() {
while (shouldRestart) {
try {
startKernel(
DefaultKernelLoggerFactory,
SpringProcessKernelRunMode,
kernelConfig,
DefaultResolutionInfoProviderFactory,
)
} catch (_: InterruptedException) {
}
}
}

override fun close() {
shouldRestart = false
kernelThread.interrupt()
}
}
9 changes: 7 additions & 2 deletions src/main/kotlin/org/jetbrains/kotlinx/jupyter/Ikotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fun kernelServer(replSettings: DefaultReplSettings) {
} catch (_: InterruptedException) {
}

logger.info("Shutdown server")
logger.info("Server is stopped")
}
}

Expand All @@ -264,10 +264,15 @@ private fun initializeKernelSession(
) {
val codeEvaluator =
CodeEvaluator { code ->
val executeRequest =
ExecuteRequest(
code,
storeHistory = false,
)
val messageData =
MessageData(
header = makeHeader(MessageType.EXECUTE_REQUEST),
content = ExecuteRequest(code),
content = executeRequest,
)
val message =
Message(
Expand Down

0 comments on commit 860d874

Please sign in to comment.