Пример #1
0
    def __init__(self, baseurl, dir):
        # This matches a kernel id (uuid4 format) from a url
        _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
        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": 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(compress_response=True,
                        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)
        self.kernel_dealer = KernelDealer(config.get("provider_settings"))
        start_providers(self.kernel_dealer.port, config.get("providers"), dir)
        self.completer = handlers.Completer(self.kernel_dealer)
        db = __import__('db_' + config.get('db'))
        self.db = db.DB(config.get('db_config')['uri'])
        self.ioloop = tornado.ioloop.IOLoop.current()

        # 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)
        super(SageCellServer, self).__init__(handlers_list, **settings)
        logger.info('SageCell server started')
        try:
            from systemd.daemon import notify
            logger.debug('notifying systemd that we are ready')
            notify('READY=1\nMAINPID={}'.format(os.getpid()), True)
        except ImportError:
            pass
Пример #2
0
    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)