##// END OF EJS Templates
cleanup connection files on notebook shutdown...
MinRK -
Show More
@@ -303,9 +303,6 b' class NotebookApp(BaseIPythonApplication):'
303 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
303 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
304
304
305 def init_configurables(self):
305 def init_configurables(self):
306 # Don't let Qt or ZMQ swallow KeyboardInterupts.
307 signal.signal(signal.SIGINT, signal.SIG_DFL)
308
309 # force Session default to be secure
306 # force Session default to be secure
310 default_secure(self.config)
307 default_secure(self.config)
311 # Create a KernelManager and start a kernel.
308 # Create a KernelManager and start a kernel.
@@ -323,10 +320,8 b' class NotebookApp(BaseIPythonApplication):'
323 # and all of its ancenstors until propagate is set to False.
320 # and all of its ancenstors until propagate is set to False.
324 self.log.propagate = False
321 self.log.propagate = False
325
322
326 @catch_config_error
323 def init_webapp(self):
327 def initialize(self, argv=None):
324 """initialize tornado webapp and httpserver"""
328 super(NotebookApp, self).initialize(argv)
329 self.init_configurables()
330 self.web_app = NotebookWebApplication(
325 self.web_app = NotebookWebApplication(
331 self, self.kernel_manager, self.notebook_manager, self.log,
326 self, self.kernel_manager, self.notebook_manager, self.log,
332 self.webapp_settings
327 self.webapp_settings
@@ -339,7 +334,7 b' class NotebookApp(BaseIPythonApplication):'
339 ssl_options = None
334 ssl_options = None
340 self.web_app.password = self.password
335 self.web_app.password = self.password
341 self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
336 self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
342 if ssl_options is None and not self.ip:
337 if ssl_options is None and not self.ip and not (self.read_only and not self.password):
343 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
338 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
344 'but not using any encryption or authentication. This is highly '
339 'but not using any encryption or authentication. This is highly '
345 'insecure and not recommended.')
340 'insecure and not recommended.')
@@ -358,6 +353,23 b' class NotebookApp(BaseIPythonApplication):'
358 self.port = port
353 self.port = port
359 break
354 break
360
355
356 @catch_config_error
357 def initialize(self, argv=None):
358 super(NotebookApp, self).initialize(argv)
359 self.init_configurables()
360 self.init_webapp()
361
362 def cleanup_kernels(self):
363 """shutdown all kernels
364
365 The kernels will shutdown themselves when this process no longer exists,
366 but explicit shutdown allows the KernelManagers to cleanup the connection files.
367 """
368 self.log.info('Shutting down kernels')
369 km = self.kernel_manager
370 while km.kernel_ids:
371 km.kill_kernel(km.kernel_ids[0])
372
361 def start(self):
373 def start(self):
362 ip = self.ip if self.ip else '[all ip addresses on your system]'
374 ip = self.ip if self.ip else '[all ip addresses on your system]'
363 proto = 'https' if self.certfile else 'http'
375 proto = 'https' if self.certfile else 'http'
@@ -371,15 +383,20 b' class NotebookApp(BaseIPythonApplication):'
371 b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
383 b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
372 new=2)
384 new=2)
373 threading.Thread(target=b).start()
385 threading.Thread(target=b).start()
374
386 try:
375 ioloop.IOLoop.instance().start()
387 ioloop.IOLoop.instance().start()
388 except KeyboardInterrupt:
389 info("Interrupted...")
390 finally:
391 self.cleanup_kernels()
392
376
393
377 #-----------------------------------------------------------------------------
394 #-----------------------------------------------------------------------------
378 # Main entry point
395 # Main entry point
379 #-----------------------------------------------------------------------------
396 #-----------------------------------------------------------------------------
380
397
381 def launch_new_instance():
398 def launch_new_instance():
382 app = NotebookApp()
399 app = NotebookApp.instance()
383 app.initialize()
400 app.initialize()
384 app.start()
401 app.start()
385
402
General Comments 0
You need to be logged in to leave comments. Login now