def __init__(self, applications, io_loop=None, http_server_kwargs=None, **kwargs):
        ''' Create a ``Server`` instance.

        Args:
            applications (dict[str, Application] or Application or callable) :
                A mapping from URL paths to Application instances, or a single
                Application to put at the root URL.

                The Application is a factory for Documents, with a new Document
                initialized for each Session. Each application is identified
                by a path that corresponds to a URL, like "/" or "/myapp"

                If a single Application is provided, it is mapped to the URL
                path "/" automatically.

                As a convenience, a callable may also be provided, in which
                an Application will be created for it using
                ``FunctionHandler``.

            io_loop (IOLoop, optional) :
                An explicit Tornado ``IOLoop`` to run Bokeh Server code on. If
                None, ``IOLoop.current()`` will be used (default: None)

            http_server_kwargs (dict, optional) :
                Extra arguments passed to ``tornado.httpserver.HTTPServer``.

                E.g. ``max_buffer_size`` to specify the maximum upload size.
                More details can be found at:

                http://www.tornadoweb.org/en/stable/httpserver.html#http-server

                If None, no extra arguments are passed (default: None)

        Additionally, the following options may be passed to configure the
        operation of ``Server``:

        .. bokeh-options:: _ServerOpts
            :module: bokeh.server.server

        Any remaining keyword arguments will be passed as-is to
        ``BokehTornado``.

        '''
        log.info("Starting Bokeh server version %s (running on Tornado %s)" % (__version__, tornado.version))

        from bokeh.application.handlers.function import FunctionHandler
        from bokeh.application.handlers.document_lifecycle import DocumentLifecycleHandler

        if callable(applications):
            applications = Application(FunctionHandler(applications))

        if isinstance(applications, Application):
            applications = { '/' : applications }

        for k, v in list(applications.items()):
            if callable(v):
                applications[k] = Application(FunctionHandler(v))
            if all(not isinstance(handler, DocumentLifecycleHandler)
                   for handler in applications[k]._handlers):
                applications[k].add(DocumentLifecycleHandler())

        opts = _ServerOpts(kwargs)
        self._port = opts.port
        self._address = opts.address
        self._prefix = opts.prefix
        self._index = opts.index

        if opts.num_procs != 1:
            assert all(app.safe_to_fork for app in applications.values()), (
                      'User application code has run before attempting to start '
                      'multiple processes. This is considered an unsafe operation.')

        if opts.num_procs > 1 and io_loop is not None:
            raise RuntimeError(
                "Setting both num_procs and io_loop in Server is incompatible. Use BaseServer to coordinate an explicit IOLoop and multi-process HTTPServer"
            )

        if opts.num_procs > 1 and sys.platform == "win32":
            raise RuntimeError("num_procs > 1 not supported on Windows")

        if http_server_kwargs is None:
            http_server_kwargs = {}
        http_server_kwargs.setdefault('xheaders', opts.use_xheaders)

        sockets, self._port = bind_sockets(self.address, self.port)

        extra_websocket_origins = create_hosts_whitelist(opts.allow_websocket_origin, self.port)
        try:
            tornado_app = BokehTornado(applications,
                                       extra_websocket_origins=extra_websocket_origins,
                                       prefix=self.prefix,
                                       index=self.index,
                                       websocket_max_message_size_bytes=opts.websocket_max_message_size,
                                       **kwargs)

            http_server = HTTPServer(tornado_app, **http_server_kwargs)

            http_server.start(opts.num_procs)
            http_server.add_sockets(sockets)

        except Exception:
            for s in sockets:
                s.close()
            raise

        # Can only refer to IOLoop after HTTPServer.start() is called, see #5524
        if io_loop is None:
            io_loop = IOLoop.current()

        super(Server, self).__init__(io_loop, tornado_app, http_server)
def __init__ ( self , applications , io_loop = None , http_server_kwargs = None , ** kwargs ) : log . info ( "Starting Bokeh server version %s (running on Tornado %s)" % ( __version__ , tornado . version ) ) from bokeh . application . handlers . function import FunctionHandler from bokeh . application . handlers . document_lifecycle import DocumentLifecycleHandler if callable ( applications ) : applications = Application ( FunctionHandler ( applications ) ) if isinstance ( applications , Application ) : applications = { '/' : applications } for k , v in list ( applications . items ( ) ) : if callable ( v ) : applications [ k ] = Application ( FunctionHandler ( v ) ) if all ( not isinstance ( handler , DocumentLifecycleHandler ) for handler in applications [ k ] . _handlers ) : applications [ k ] . add ( DocumentLifecycleHandler ( ) ) opts = _ServerOpts ( kwargs ) self . _port = opts . port self . _address = opts . address self . _prefix = opts . prefix self . _index = opts . index if opts . num_procs != 1 : assert all ( app . safe_to_fork for app in applications . values ( ) ) , ( 'User application code has run before attempting to start ' 'multiple processes. This is considered an unsafe operation.' ) if opts . num_procs > 1 and io_loop is not None : raise RuntimeError ( "Setting both num_procs and io_loop in Server is incompatible. Use BaseServer to coordinate an explicit IOLoop and multi-process HTTPServer" ) if opts . num_procs > 1 and sys . platform == "win32" : raise RuntimeError ( "num_procs > 1 not supported on Windows" ) if http_server_kwargs is None : http_server_kwargs = { } http_server_kwargs . setdefault ( 'xheaders' , opts . use_xheaders ) sockets , self . _port = bind_sockets ( self . address , self . port ) extra_websocket_origins = create_hosts_whitelist ( opts . allow_websocket_origin , self . port ) try : tornado_app = BokehTornado ( applications , extra_websocket_origins = extra_websocket_origins , prefix = self . prefix , index = self . index , websocket_max_message_size_bytes = opts . websocket_max_message_size , ** kwargs ) http_server = HTTPServer ( tornado_app , ** http_server_kwargs ) http_server . start ( opts . num_procs ) http_server . add_sockets ( sockets ) except Exception : for s in sockets : s . close ( ) raise if io_loop is None : io_loop = IOLoop . current ( ) super ( Server , self ) . __init__ ( io_loop , tornado_app , http_server )
Create a ``Server`` instance.

        Args:
            applications (dict[str, Application] or Application or callable) :
                A mapping from URL paths to Application instances, or a single
                Application to put at the root URL.

                The Application is a factory for Documents, with a new Document
                initialized for each Session. Each application is identified
                by a path that corresponds to a URL, like "/" or "/myapp"

                If a single Application is provided, it is mapped to the URL
                path "/" automatically.

                As a convenience, a callable may also be provided, in which
                an Application will be created for it using
                ``FunctionHandler``.

            io_loop (IOLoop, optional) :
                An explicit Tornado ``IOLoop`` to run Bokeh Server code on. If
                None, ``IOLoop.current()`` will be used (default: None)

            http_server_kwargs (dict, optional) :
                Extra arguments passed to ``tornado.httpserver.HTTPServer``.

                E.g. ``max_buffer_size`` to specify the maximum upload size.
                More details can be found at:

                http://www.tornadoweb.org/en/stable/httpserver.html#http-server

                If None, no extra arguments are passed (default: None)

        Additionally, the following options may be passed to configure the
        operation of ``Server``:

        .. bokeh-options:: _ServerOpts
            :module: bokeh.server.server

        Any remaining keyword arguments will be passed as-is to
        ``BokehTornado``.