From 8c5ce96eaabf0b83709c5b63d8f79e6719460075 2013-07-28 00:11:19 From: damianavila Date: 2013-07-28 00:11:19 Subject: [PATCH] Capturing Keyboard interrupt. --- diff --git a/IPython/nbconvert/post_processors/serve.py b/IPython/nbconvert/post_processors/serve.py index 022322f..9f95856 100644 --- a/IPython/nbconvert/post_processors/serve.py +++ b/IPython/nbconvert/post_processors/serve.py @@ -37,9 +37,12 @@ class ServePostProcessor(PostProcessorBase): Simple implementation to serve the build directory. """ - os.chdir(self.build_directory) - httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) - sa = httpd.socket.getsockname() - print("Serving '" + input + "' nbconverted from ipynb on http://" + sa[0] + ":" + str(sa[1]) + "/") - print("Use Control-C to stop this server.") - httpd.serve_forever() + try: + os.chdir(self.build_directory) + httpd = HTTPServer(('127.0.0.1', 8000), SimpleHTTPRequestHandler) + sa = httpd.socket.getsockname() + print("Serving " + input[2:] + " on http://" + sa[0] + ":" + str(sa[1])) + print("Use Control-C to stop this server.") + httpd.serve_forever() + except KeyboardInterrupt: + print("The server is shut down.")