I think IPython.notebook.session.delete()
is better than IPython.notebook.kernel.kill()
.
window.addEventListener('unload', function() {
// For Firefox
IPython.notebook.session.delete();
});
window.onbeforeunload = function () {
// For Chrome
IPython.notebook.session.delete();
};
Reason
Because kernel.kill()
will just kill kernel. It won't tell notebook's sessionmanager about killing it.
So after killing, sessionmanager will raise KernelError
when you'll reopen the same ipynb file which you closed by kernel.kill()
(closed tabs or windows).
About unload
On GoogleChrome, unload events won't be fired on moving pages.
So, I think you should also hook beforeunload
event
But hooking by addEventListener('beforeunload', ...)
didn't work.
So I tried window.onbeforeunload =
and it works fine.