Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.09k stars 106 forks source link

Add onInterrupt to the API #369

Closed Jolanrensen closed 2 years ago

Jolanrensen commented 2 years ago

Sometimes a cell needs some extra cleanup to be done when the Jupyter kernel is interrupted, such as closing specific threads it spawned etc. afterCellExecution {} does not appear to be called in this case and when trying to use a finally block (piggybacking on the InterruptedException) in the integration code to make sure the other threads stop, this also gets interrupted (I think). I, at least, was not able to get a working clean solution.

A block of code that can run after an interrupt of the kernel could solve this as it has some time to clean up and make sure any running process is stopped as well.