I am trying to detect a kernel restart inside an Extension to trigger an action in the Extension.
The top-level application object provides a reference to the service manager for session from which I can listen to changes in session: app.serviceManager.sessions.runningChanged
But this does not help to reliably detect a kernel restart. Would appreciate any pointers towards identifying change in kernel state to ‘restarting’. Thanks.
Currently debugger already reacts to kernel restarts (in a way), but it seems to be listening on kernelChanged instead (see handler.ts). I wonder if this is emitted on restarts too? It would be good to experiment if you are interested in this (I don’t have time right now and cannot guarantee it will succeed but if you really need that it might be worth a try).
thanks! If I have some time this weekend I’ll take a look at debugger/how it handles restarts. I’m guessing I’ll need to pip install xeus-python notebook to get the debugger working properly?
I found this line in sessioncontext which looks like it produces a signal when restarting the kernel, but not quite sure how to watch for that signal to change.
Additionally - and not sure if this is relevant to your use case @Nishchay - is there a way to check if a notebook has finished executing cells? I’m interested in having a dialog box show up after restarting and running all cells, which I’m realizing is slightly trickier than just checking whether a notebook has restarted…