当前位置: 首页>>代码示例>>Python>>正文


Python Server.start方法代码示例

本文整理汇总了Python中bokeh.server.server.Server.start方法的典型用法代码示例。如果您正苦于以下问题:Python Server.start方法的具体用法?Python Server.start怎么用?Python Server.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bokeh.server.server.Server的用法示例。


在下文中一共展示了Server.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BokehServer

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
class BokehServer(object):
    def listen(self, port):
        if self.server:
            return
        for i in range(5):
            try:
                self.server = Server(self.apps, io_loop=self.loop, port=port,
                                     check_unused_sessions_milliseconds=500,
                                     host=['*'])
                self.server.start(start_loop=False)
                break
            except (SystemExit, EnvironmentError):
                port = 0
                if i == 4:
                    raise

    @property
    def port(self):
        return (self.server.port or
                list(self.server._http._sockets.values())[0].getsockname()[1])

    def stop(self):
        for context in self.server._tornado._applications.values():
            context.run_unload_hook()

        self.server._tornado._stats_job.stop()
        self.server._tornado._cleanup_job.stop()
        if self.server._tornado._ping_job is not None:
            self.server._tornado._ping_job.stop()
开发者ID:dask,项目名称:distributed,代码行数:31,代码来源:core.py

示例2: invoke

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def invoke(self, args):
        applications = build_single_handler_applications(args.files)

        log_level = getattr(logging, args.log_level.upper())
        logging.basicConfig(level=log_level)

        if len(applications) == 0:
            # create an empty application by default, typically used with output_server
            applications['/'] = Application()

        server = Server(applications, port=args.port, address=args.address)

        if args.show:
            # we have to defer opening in browser until we start up the server
            def show_callback():
                for route in applications.keys():
                    server.show(route)
            server.io_loop.add_callback(show_callback)

        if args.develop:
            log.info("Using develop mode (do not enable --develop in production)")

        address_string = ''
        if server.address is not None and server.address != '':
            address_string = ' address ' + server.address

        log.info("Starting Bokeh server on port %d%s with applications at paths %r",
                 server.port,
                 address_string,
                 sorted(applications.keys()))

        server.start()
开发者ID:brianpanneton,项目名称:bokeh,代码行数:34,代码来源:serve.py

示例3: func

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def func(self, args):
        if args.port >= 0:
            self.port = args.port

        self.develop_mode = args.develop

        applications = self.build_applications(args)

        # TODO make log level a command line option
        logging.basicConfig(level=logging.DEBUG)

        server = Server(applications, port=self.port, address=args.address)

        if args.show:
            # we have to defer opening in browser until
            # we start up the server
            def show_callback():
                for route in applications.keys():
                    server.show(route)
            server.io_loop.add_callback(show_callback)

        if self.develop_mode:
            log.info("Using develop mode (do not enable --develop in production)")
        address_string = ''
        if server.address is not None and server.address != '':
            address_string = ' address ' + server.address
        log.info("Starting Bokeh server on port %d%s with applications at paths %r",
                 server.port,
                 address_string,
                 sorted(applications.keys()))
        server.start()
开发者ID:Jessime,项目名称:bokeh,代码行数:33,代码来源:__init__.py

示例4: worker

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
 def worker():
     io_loop = IOLoop()
     server = Server({'/': modify_doc},
                     port=port,
                     io_loop=io_loop,
                     extra_patterns=[('/exit', _ExitHandler, dict(io_loop=io_loop))])
     server.start()
     server.io_loop.start()
开发者ID:jakirkham,项目名称:bokeh,代码行数:10,代码来源:bokeh.py

示例5: Bokeh_Worker

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
class Bokeh_Worker(Thread):

    # Init thread running server
    def __init__(self, dev_app, trends_app, notes_app, serverIP, *, daemon=True):
        Thread.__init__(self, daemon=daemon)
        self._dev_app_ref = weakref.ref(dev_app)
        self._trends_app_ref = weakref.ref(trends_app)
        self._notes_app_ref = weakref.ref(notes_app)
        self.IP = serverIP
        self.exitFlag = False

    def run(self):
        self.process()

    def process(self):
        while not self.exitFlag:
            self.task()

    def startServer(self):
        self.server = Server(
            {
                "/devices": self._dev_app_ref(),
                "/trends": self._trends_app_ref(),
                "/notes": self._notes_app_ref(),
            },
            io_loop=IOLoop(),
            allow_websocket_origin=[
                "{}:8111".format(self.IP),
                "{}:5006".format(self.IP),
                "{}:8111".format("localhost"),
                "{}:5006".format("localhost"),
            ],
        )
        self.server.start()
        self.server.io_loop.start()

    def task(self):
        try:
            self.startServer()
        except Exception as err:
            self._log.warning("Bokeh server already running", err)
            self.exitFlag = True

    def stop(self):
        self.bokeh_server.stop()
        self.exitFlag = True

    def beforeStop(self):
        """
        Action done when closing thread
        """
        pass
开发者ID:ChristianTremblay,项目名称:BAC0,代码行数:54,代码来源:BokehServer.py

示例6: func

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def func(self, args):
        if args.port >= 0:
            self.port = args.port

        self.develop_mode = args.develop

        applications = self.build_applications(args)

        # TODO make log level a command line option
        logging.basicConfig(level=logging.DEBUG)

        server = Server(applications, port=self.port)
        if self.develop_mode:
            log.info("Using develop mode (do not enable --develop in production)")
        log.info("Starting Bokeh server on port %d with apps at %r", server.port, sorted(applications.keys()))
        server.start()
开发者ID:rbtr,项目名称:bokeh,代码行数:18,代码来源:__init__.py

示例7: ManagedServerLoop

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
class ManagedServerLoop(object):
    def __init__(self, application, **server_kwargs):
        loop = IOLoop()
        loop.make_current()
        server_kwargs['io_loop'] = loop
        self._server = Server(application, **server_kwargs)
    def __exit__(self, type, value, traceback):
        self._server.unlisten()
        self._server.stop()
        self._server.io_loop.close()
    def __enter__(self):
        self._server.start()
        return self._server
    @property
    def io_loop(self):
        return self.s_server.io_loop
开发者ID:jfinkels,项目名称:bokeh,代码行数:18,代码来源:utils.py

示例8: invoke

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def invoke(self, args):
        applications = build_single_handler_applications(args.files)

        log_level = getattr(logging, args.log_level.upper())
        logging.basicConfig(level=log_level)

        if len(applications) == 0:
            # create an empty application by default, typically used with output_server
            applications['/'] = Application()

        if args.keep_alive is not None:
            if args.keep_alive == 0:
                log.info("Keep-alive ping disabled")
            else:
                log.info("Keep-alive ping configured every %d milliseconds", args.keep_alive)
            # rename to be compatible with Server
            args.keep_alive_milliseconds = args.keep_alive

        server_kwargs = { key: getattr(args, key) for key in ['port',
                                                              'address',
                                                              'host',
                                                              'prefix',
                                                              'keep_alive_milliseconds']
                          if getattr(args, key, None) is not None }

        server = Server(applications, **server_kwargs)

        if args.show:
            # we have to defer opening in browser until we start up the server
            def show_callback():
                for route in applications.keys():
                    server.show(route)
            server.io_loop.add_callback(show_callback)

        if args.develop:
            log.info("Using develop mode (do not enable --develop in production)")

        address_string = ''
        if server.address is not None and server.address != '':
            address_string = ' address ' + server.address

        log.info("Starting Bokeh server on port %d%s with applications at paths %r",
                 server.port,
                 address_string,
                 sorted(applications.keys()))

        server.start()
开发者ID:SandraKilpatrick,项目名称:bokeh,代码行数:49,代码来源:serve.py

示例9: invoke

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def invoke(self, args):
        log_level = getattr(logging, args.log_level.upper())
        logging.basicConfig(level=log_level, format=args.log_format)

        applications = {}

        _allowed_keys = ['port', 'address']
        server_kwargs = { key: getattr(args, key) for key in _allowed_keys if getattr(args, key, None) is not None }

        server = Server(applications, **server_kwargs)

        address_string = ''
        if server.address is not None and server.address != '':
            address_string = ' address ' + server.address

        log.info("Starting Bokeh static server on port %d%s", server.port, address_string)
        server.start()
开发者ID:0-T-0,项目名称:bokeh,代码行数:19,代码来源:static.py

示例10: finish

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def finish(self):
        if not self.disable_server:
            def modify_doc(doc):
                doc.add_root(self.layout)
                doc.title = self.name

                directory = os.path.abspath(os.path.dirname(__file__))
                theme_path = os.path.join(directory, "theme.yaml")
                template_path = os.path.join(directory, "templates")
                doc.theme = Theme(filename=theme_path)
                env = jinja2.Environment(
                    loader=jinja2.FileSystemLoader(template_path)
                )
                doc.template = env.get_template('index.html')

            self.log.info('Opening Bokeh application on '
                          'http://localhost:{}/'.format(self.port))
            server = Server({'/': modify_doc}, num_procs=1, port=self.port)
            server.start()
            server.io_loop.add_callback(server.show, "/")
            server.io_loop.start()
开发者ID:ParsonsRD,项目名称:ctapipe,代码行数:23,代码来源:file_viewer.py

示例11: invoke

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def invoke(self, args):
        applications = build_single_handler_applications(args.files)

        log_level = getattr(logging, args.log_level.upper())
        logging.basicConfig(level=log_level)

        if len(applications) == 0:
            # create an empty application by default, typically used with output_server
            applications['/'] = Application()

        if args.keep_alive is not None:
            if args.keep_alive == 0:
                log.info("Keep-alive ping disabled")
            else:
                log.info("Keep-alive ping configured every %d milliseconds", args.keep_alive)
            # rename to be compatible with Server
            args.keep_alive_milliseconds = args.keep_alive

        server_kwargs = { key: getattr(args, key) for key in ['port',
                                                              'address',
                                                              'allow_websocket_origin',
                                                              'host',
                                                              'prefix',
                                                              'develop',
                                                              'keep_alive_milliseconds',
                                                              'use_xheaders',
                                                            ]
                          if getattr(args, key, None) is not None }

        server_kwargs['sign_sessions'] = settings.sign_sessions()
        server_kwargs['secret_key'] = settings.secret_key_bytes()
        server_kwargs['generate_session_ids'] = True
        if args.session_ids is None:
            # no --session-ids means use the env vars
            pass
        elif args.session_ids == 'unsigned':
            server_kwargs['sign_sessions'] = False
        elif args.session_ids == 'signed':
            server_kwargs['sign_sessions'] = True
        elif args.session_ids == 'external-signed':
            server_kwargs['sign_sessions'] = True
            server_kwargs['generate_session_ids'] = False
        else:
            raise RuntimeError("argparse should have filtered out --session-ids mode " +
                               args.session_ids)

        if server_kwargs['sign_sessions'] and not server_kwargs['secret_key']:
            die("To sign sessions, the BOKEH_SECRET_KEY environment variable must be set; " +
                "the `bokeh secret` command can be used to generate a new key.")

        server = Server(applications, **server_kwargs)

        if args.show:
            # we have to defer opening in browser until we start up the server
            def show_callback():
                for route in applications.keys():
                    server.show(route)
            server.io_loop.add_callback(show_callback)

        if args.develop:
            log.info("Using develop mode (do not enable --develop in production)")

        address_string = ''
        if server.address is not None and server.address != '':
            address_string = ' address ' + server.address

        log.info("Starting Bokeh server on port %d%s with applications at paths %r",
                 server.port,
                 address_string,
                 sorted(applications.keys()))

        server.start()
开发者ID:mvictor212,项目名称:bokeh,代码行数:74,代码来源:serve.py

示例12: app

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def app(self_or_cls, plot, show=False, new_window=False, websocket_origin=None, port=0):
        """
        Creates a bokeh app from a HoloViews object or plot. By
        default simply attaches the plot to bokeh's curdoc and returns
        the Document, if show option is supplied creates an
        Application instance and displays it either in a browser
        window or inline if notebook extension has been loaded.  Using
        the new_window option the app may be displayed in a new
        browser tab once the notebook extension has been loaded.  A
        websocket origin is required when launching from an existing
        tornado server (such as the notebook) and it is not on the
        default port ('localhost:8888').
        """
        if not isinstance(self_or_cls, BokehRenderer) or self_or_cls.mode != 'server':
            renderer = self_or_cls.instance(mode='server')
        else:
            renderer = self_or_cls

        def modify_doc(doc):
            renderer(plot, doc=doc)
        handler = FunctionHandler(modify_doc)
        app = Application(handler)

        if not show:
            # If not showing and in notebook context return app
            return app
        elif self_or_cls.notebook_context and not new_window:
            # If in notebook, show=True and no new window requested
            # display app inline
            if isinstance(websocket_origin, list):
                if len(websocket_origin) > 1:
                    raise ValueError('In the notebook only a single websocket origin '
                                     'may be defined, which must match the URL of the '
                                     'notebook server.')
                websocket_origin = websocket_origin[0]
            opts = dict(notebook_url=websocket_origin) if websocket_origin else {}
            return bkshow(app, **opts)

        # If app shown outside notebook or new_window requested
        # start server and open in new browser tab
        from tornado.ioloop import IOLoop
        loop = IOLoop.current()
        if websocket_origin and not isinstance(websocket_origin, list):
            websocket_origin = [websocket_origin]
        opts = dict(allow_websocket_origin=websocket_origin) if websocket_origin else {}
        opts['io_loop'] = loop
        server = Server({'/': app}, port=port, **opts)
        def show_callback():
            server.show('/')
        server.io_loop.add_callback(show_callback)
        server.start()

        def sig_exit(*args, **kwargs):
            loop.add_callback_from_signal(do_stop)

        def do_stop(*args, **kwargs):
            loop.stop()

        signal.signal(signal.SIGINT, sig_exit)
        try:
            loop.start()
        except RuntimeError:
            pass
        return server
开发者ID:basnijholt,项目名称:holoviews,代码行数:66,代码来源:renderer.py

示例13: BokehServer

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
class BokehServer(object):
    server_kwargs = {}

    def listen(self, addr):
        if self.server:
            return
        if isinstance(addr, tuple):
            ip, port = addr
        else:
            port = addr
            ip = None
        for i in range(5):
            try:
                self.server = Server(self.apps,
                                     port=port, address=ip,
                                     check_unused_sessions_milliseconds=500,
                                     allow_websocket_origin=["*"],
                                     use_index=False,
                                     extra_patterns=[(r'/', web.RedirectHandler, {'url': '/status'})],
                                     **self.server_kwargs)
                self.server.start()

                handlers = [(self.prefix + r'/statics/(.*)',
                             web.StaticFileHandler,
                             {'path': os.path.join(os.path.dirname(__file__), 'static')})]

                self.server._tornado.add_handlers(r'.*', handlers)

                return
            except (SystemExit, EnvironmentError) as exc:
                if port != 0:
                    if ("already in use" in str(exc) or  # Unix/Mac
                            "Only one usage of" in str(exc)):  # Windows
                        msg = ("Port %d is already in use. "
                               "\nPerhaps you already have a cluster running?"
                               "\nHosting the diagnostics dashboard on a random port instead."
                               % port)
                    else:
                        msg = "Failed to start diagnostics server on port %d. " % port + str(exc)
                    warnings.warn('\n' + msg)
                    port = 0
                if i == 4:
                    raise

    @property
    def port(self):
        return (self.server.port or
                list(self.server._http._sockets.values())[0].getsockname()[1])

    def stop(self):
        for context in self.server._tornado._applications.values():
            context.run_unload_hook()

        self.server._tornado._stats_job.stop()
        self.server._tornado._cleanup_job.stop()
        if self.server._tornado._ping_job is not None:
            self.server._tornado._ping_job.stop()

        # https://github.com/bokeh/bokeh/issues/5494
        if LooseVersion(bokeh.__version__) >= '0.12.4':
            self.server.stop()
开发者ID:tomMoral,项目名称:distributed,代码行数:63,代码来源:core.py

示例14: callback

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def callback(attr, old, new):
        if new == 0:
            data = df
        else:
            data = df.rolling('{0}D'.format(new)).mean()
        source.data = ColumnDataSource(data=data).data

    slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
    slider.on_change('value', callback)

    doc.add_root(column(slider, plot))

    doc.theme = Theme(filename="theme.yaml")

bokeh_app = Application(FunctionHandler(modify_doc))

# Setting num_procs here means we can't touch the IOLoop before now, we must
# let Server handle that. If you need to explicitly handle IOLoops then you
# will need to use the lower level BaseServer class.
server = Server({'/bkapp': bokeh_app}, num_procs=4, extra_patterns=[('/', IndexHandler)])
server.start()

if __name__ == '__main__':
    from bokeh.util.browser import view

    print('Opening Tornado app with embedded Bokeh application on http://localhost:5006/')

    server.io_loop.add_callback(view, "http://localhost:5006/")
    server.io_loop.start()
开发者ID:alamont,项目名称:bokeh,代码行数:31,代码来源:tornado_embed.py

示例15: invoke

# 需要导入模块: from bokeh.server.server import Server [as 别名]
# 或者: from bokeh.server.server.Server import start [as 别名]
    def invoke(self, args):
        applications = build_single_handler_applications(args.files)

        log_level = getattr(logging, args.log_level.upper())
        logging.basicConfig(level=log_level)

        if len(applications) == 0:
            # create an empty application by default, typically used with output_server
            applications["/"] = Application()

        if args.keep_alive is not None:
            if args.keep_alive == 0:
                log.info("Keep-alive ping disabled")
            else:
                log.info("Keep-alive ping configured every %d milliseconds", args.keep_alive)
            # rename to be compatible with Server
            args.keep_alive_milliseconds = args.keep_alive

        if args.check_unused_sessions is not None:
            log.info("Check for unused sessions every %d milliseconds", args.check_unused_sessions)
            # rename to be compatible with Server
            args.check_unused_sessions_milliseconds = args.check_unused_sessions

        if args.unused_session_lifetime is not None:
            log.info("Unused sessions last for %d milliseconds", args.unused_session_lifetime)
            # rename to be compatible with Server
            args.unused_session_lifetime_milliseconds = args.unused_session_lifetime

        if args.stats_log_frequency is not None:
            log.info("Log statistics every %d milliseconds", args.stats_log_frequency)
            # rename to be compatible with Server
            args.stats_log_frequency_milliseconds = args.stats_log_frequency

        server_kwargs = {
            key: getattr(args, key)
            for key in [
                "port",
                "address",
                "allow_websocket_origin",
                "host",
                "prefix",
                "develop",
                "keep_alive_milliseconds",
                "check_unused_sessions_milliseconds",
                "unused_session_lifetime_milliseconds",
                "stats_log_frequency_milliseconds",
                "use_xheaders",
            ]
            if getattr(args, key, None) is not None
        }

        server_kwargs["sign_sessions"] = settings.sign_sessions()
        server_kwargs["secret_key"] = settings.secret_key_bytes()
        server_kwargs["generate_session_ids"] = True
        if args.session_ids is None:
            # no --session-ids means use the env vars
            pass
        elif args.session_ids == "unsigned":
            server_kwargs["sign_sessions"] = False
        elif args.session_ids == "signed":
            server_kwargs["sign_sessions"] = True
        elif args.session_ids == "external-signed":
            server_kwargs["sign_sessions"] = True
            server_kwargs["generate_session_ids"] = False
        else:
            raise RuntimeError("argparse should have filtered out --session-ids mode " + args.session_ids)

        if server_kwargs["sign_sessions"] and not server_kwargs["secret_key"]:
            die(
                "To sign sessions, the BOKEH_SECRET_KEY environment variable must be set; "
                + "the `bokeh secret` command can be used to generate a new key."
            )

        server = Server(applications, **server_kwargs)

        if args.show:
            # we have to defer opening in browser until we start up the server
            def show_callback():
                for route in applications.keys():
                    server.show(route)

            server.io_loop.add_callback(show_callback)

        if args.develop:
            log.info("Using develop mode (do not enable --develop in production)")

        address_string = ""
        if server.address is not None and server.address != "":
            address_string = " address " + server.address

        log.info(
            "Starting Bokeh server on port %d%s with applications at paths %r",
            server.port,
            address_string,
            sorted(applications.keys()),
        )

        server.start()
开发者ID:CrashClark,项目名称:bokeh,代码行数:100,代码来源:serve.py


注:本文中的bokeh.server.server.Server.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。