From 3c19b40d2fb923462b0951497670286276b8140e Mon Sep 17 00:00:00 2001 From: MinRK Date: Sun, 15 Apr 2012 12:05:59 -0700 Subject: [PATCH] exit notebook cleanly on SIGINT, SIGTERM makes it a bit more likely security files, etc. will be cleaned up. --- IPython/frontend/html/notebook/notebookapp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index 8f4f10a38..a43842e50 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -449,11 +449,20 @@ class NotebookApp(BaseIPythonApplication): self.port = port break + def init_signal(self): + signal.signal(signal.SIGINT, self._handle_signal) + signal.signal(signal.SIGTERM, self._handle_signal) + + def _handle_signal(self, sig, frame): + self.log.critical("received signal %s, stopping", sig) + ioloop.IOLoop.instance().stop() + @catch_config_error def initialize(self, argv=None): super(NotebookApp, self).initialize(argv) self.init_configurables() self.init_webapp() + self.init_signal() def cleanup_kernels(self): """shutdown all kernels