class SageCellServer(tornado.web.Application): def __init__(self): handlers = [ (r"/kernel/%s/iopub" % _kernel_id_regex, IOPubHandler), (r"/kernel/%s/shell" % _kernel_id_regex, ShellHandler), (r".*", tornado.web.FallbackHandler, {'fallback': wsgi_app}) ] self.km = TMKM() self.km.setup_initial_comps() super(SageCellServer, self).__init__(handlers)
def __init__(self, baseurl=""): # This matches a kernel id (uuid4 format) from a url _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)" self.config = misc.Config() baseurl = baseurl.rstrip('/') handlers_list = [ (r"/", handlers.RootHandler), (r"/embedded_sagecell.js", tornado.web.RedirectHandler, { "url": baseurl + "/static/embedded_sagecell.js" }), (r"/help.html", handlers.HelpHandler), (r"/kernel", handlers.KernelHandler), (r"/kernel/%s" % _kernel_id_regex, handlers.KernelHandler), (r"/kernel/%s/channels" % _kernel_id_regex, handlers.WebChannelsHandler), (r"/kernel/%s/files/(?P<file_path>.*)" % _kernel_id_regex, handlers.FileHandler, { "path": tmp_dir }), (r"/permalink", permalink.PermalinkHandler), (r"/service", handlers.ServiceHandler), (r"/tos.html", handlers.TOSHandler), ] + handlers.KernelRouter.urls handlers_list = [[baseurl + i[0]] + list(i[1:]) for i in handlers_list] settings = dict(template_path=os.path.join( os.path.dirname(os.path.abspath(__file__)), "templates"), static_path=os.path.join( os.path.dirname(os.path.abspath(__file__)), "static"), static_url_prefix=baseurl + "/static/", static_handler_class=handlers.StaticHandler) initial_comps = self.config.get_config("computers") default_comp = self.config.get_default_config("_default_config") max_kernel_timeout = self.config.get_config("max_kernel_timeout") self.km = TrustedMultiKernelManager( computers=initial_comps, default_computer_config=default_comp, max_kernel_timeout=max_kernel_timeout, tmp_dir=tmp_dir) db = __import__('db_' + self.config.get_config('db')) self.db = db.DB(self.config.get_config('db_config')['uri']) self.ioloop = zmq.eventloop.IOLoop.instance() # to check for blocking when debugging, uncomment the following # and set the argument to the blocking timeout in seconds self.ioloop.set_blocking_log_threshold(.5) self.completer = handlers.Completer(self.km) super(SageCellServer, self).__init__(handlers_list, **settings)