"""
Copyright (c) 2015 Phosphor Contributors
Distributed under the terms of the BSD 3-Clause License.
The full license is in the file LICENSE, distributed with this software.
"""
import subprocess
import sys
import threading

import tornado.web

PORT = 8765


class MainPageHandler(tornado.web.RequestHandler):

    def get(self):
        return self.render("index.html", static=self.static_url)


def main(argv):

    url = "http://localhost:%s" % PORT

    handlers = [
        (r"/", MainPageHandler),
        (r'/(.*)', tornado.web.StaticFileHandler, {'path': '.'}),
    ]

    nb_command = [sys.executable, '-m', 'notebook', '--no-browser', '--debug',
                  '--NotebookApp.allow_origin="%s"' % url]
    nb_server = subprocess.Popen(nb_command, stderr=subprocess.STDOUT,
                                 stdout=subprocess.PIPE)

    # wait for notebook server to start up
    while 1:
        line = nb_server.stdout.readline().decode('utf-8').strip()
        if not line:
            continue
        print(line)
        if 'The IPython Notebook is running at: http://localhost:8888/':
            break
        if 'Control-C' in line:
            raise ValueError('The port 8888 was already taken, kill running '
                             'notebook servers')

    def print_thread():
        while 1:
            line = nb_server.stdout.readline().decode('utf-8').strip()
            if not line:
                continue
            print(line)
    thread = threading.Thread(target=print_thread, daemon=True)
    thread.start()

    app = tornado.web.Application(handlers, static_path='build',
                                  template_path='.')

    app.listen(PORT, 'localhost')
    loop = tornado.ioloop.IOLoop.instance()
    print('Browse to http://localhost:%s' % PORT)
    try:
        loop.start()
    except KeyboardInterrupt:
        print(" Shutting down on SIGINT")
    finally:
        nb_server.kill()
        loop.close()

if __name__ == '__main__':
    main(sys.argv)

@@ -1270,24 +1270,217 @@
  servers')%0A%0A
+    while 1:%0A        line = nb_server.stdout.readline().decode('utf-8').strip()%0A        if not line:%0A            continue%0A        print(line)%0A        if 'Control-C' in line:%0A            break%0A%0A
     def prin

Clean up server script