I think IPython.notebook.session.delete() better than IPython.notebook.kernel.kill() .
window.addEventListener('unload', function() {
Cause
Because kernel.kill() will just kill the kernel. This will not tell the laptop session manager about the kill. Therefore, after killing, sessionmanager raises a KernelError when you open the same ipynb file again that you closed on kernel.kill() (closed tabs or windows).
About unloading
In GoogleChrome, unloading events will not be triggered on moving pages. So, I think you should also catch the beforeunload event
But intercepting addEventListener('beforeunload', ...) did not work. So I tried window.onbeforeunload = and it works fine.
hirokiky
source share