def bk_worker(sockets, port): """ Worker thread to run Bokeh Server """ asyncio.set_event_loop(asyncio.new_event_loop()) websocket_origins = [f"{BOKEH_ADDR}:{port}", f"{FLASK_ADDR}:{FLASK_PORT}"] # bokeh applications _bkapp_maps = Application(FunctionHandler(bkapp_maps)) _bkapp_trends = Application(FunctionHandler(bkapp_trends)) _bkapp_histograms = Application(FunctionHandler(bkapp_histograms)) _bkapp_models = Application(FunctionHandler(bkapp_models)) bokeh_tornado = BokehTornado( { '/bkapp-maps': _bkapp_maps, '/bkapp-trends': _bkapp_trends, '/bkapp-histograms': _bkapp_histograms, '/bkapp-models': _bkapp_models }, extra_websocket_origins=websocket_origins, **{'use_xheaders': True}) bokeh_http = HTTPServer(bokeh_tornado, xheaders=True) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): set_event_loop(new_event_loop()) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["localhost:5000", "graphion.uddi.ng:*"]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): asyncio.set_event_loop(asyncio.new_event_loop()) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["localhost:8000"]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): # An Input/Output event loop for non-blocking sockets (from tornado) io_loop = IOLoop.instance() # Explicitly coordinate the level Tornado components # required to run a Bokeh server: # - IOLoop to run the Bokeh server machinery. # - Tornado application that defines the Bokeh server machinery. # - HTTPServer to direct HTTP requests server = BaseServer(io_loop, bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(bokehsockets, flask_port): bokeh_tornado = BokehTornado({'/bokeh': bkapp}, extra_websocket_origins=["localhost", "127.0.0.1", "0.0.0.0", "*" ]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(bokehsockets) io_loop = IOLoop.current() server = BaseServer(io_loop, bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(bk_app_function, sockets): # can't use shortcuts here, since we are passing to low level BokehTornado bkapp = Application(FunctionHandler(bk_app_function)) asyncio.set_event_loop(asyncio.new_event_loop()) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["localhost:8000"]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): # starts multiple bokeh server asyncio.set_event_loop(asyncio.new_event_loop()) # bokeh setup bokeh_tornado = BokehTornado({'/bkapp': bkapp},\ extra_websocket_origins=['localhost:8080','127.0.0.1:8080']) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) # start server server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start() # output script, div = components(plot) return script, div
def bk_worker(sockets, port): """ Worker thread to run Bokeh Server """ _bkapp = Application(FunctionHandler(bkapp)) asyncio.set_event_loop(asyncio.new_event_loop()) websocket_origins = [f"{BOKEH_ADDR}:{port}", f"{FLASK_ADDR}:{FLASK_PORT}"] bokeh_tornado = BokehTornado({BOKEH_PATH: _bkapp}, extra_websocket_origins=websocket_origins, **{'use_xheaders': True}) bokeh_http = HTTPServer(bokeh_tornado, xheaders=True) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bokeh_worker(self): asyncio.set_event_loop(asyncio.new_event_loop()) sockets, port = bind_sockets(self.hostname, self.port) extra_websocket_origins = [ "{}:{}".format(self.hostname, self.port), "{}:{}".format(self.hostname, self.agent.web.port) ] bokeh_tornado = BokehTornado( self.apps, extra_websocket_origins=extra_websocket_origins) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) self.server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) self.server.start() self.server.io_loop.start()
def test_base_server() -> None: app = BokehTornado(Application()) httpserver = HTTPServer(app) httpserver.start() loop = IOLoop() loop.make_current() server = BaseServer(loop, app, httpserver) server.start() assert server.io_loop == loop assert server._tornado.io_loop == loop httpserver.stop() server.stop() server.io_loop.close()
def bk_worker(sockets, port): """ Worker thread to run Bokeh Server """ asyncio.set_event_loop(asyncio.new_event_loop()) websocket_origins = [f"{BOKEH_ADDR}:{port}", f"{FLASK_ADDR}:{FLASK_PORT}"] bokeh_tornado = BokehTornado({"/bkapp-blue": _bkapp_blue, "/bkapp-red": _bkapp_red, "/bkapp-table": _bkapp_table}, extra_websocket_origins=websocket_origins, **{'use_xheaders': True}) bokeh_http = HTTPServer(bokeh_tornado, xheaders=True) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): # Can't pass num_procs > 1 in this configuration. If you need to run multiple # processes, see e.g. flask_gunicorn_embed.py # server = Server({'/bkapp': bk.start_doc()}, io_loop=IOLoop(), allow_websocket_origin=['127.0.0.1:5000', '127.0.0.1:3000', '127.0.0.1:8000', 'localhost:3000', 'localhost:5000', 'localhost:8000'], relative_urls=True) # server.start() # server.io_loop.start() print('Starting worker...') print(app) asyncio.set_event_loop(asyncio.new_event_loop()) bokeh_tornado = BokehTornado({'/bkapp': bk.start_doc(app)}, extra_websocket_origins=['127.0.0.1:5000', '127.0.0.1:3000', '127.0.0.1:8000', 'localhost:3000', 'localhost:5000', 'localhost:8000'], relative_urls=True, appcontext=app) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(app.config['sockets']) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
def bk_worker(): asyncio.set_event_loop(asyncio.new_event_loop()) # Die Bokeh Tornado Instanz. Wichtig ist hier unter "extra_websocket_origins" den Flask-Sever IP:Port anzugeben, sonst nimmt Tornado den Websocket nicht an bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=[ "localhost:8000", "127.0.0.1:8000", ]) # Der Tornado Http-Server bokeh_http = HTTPServer(bokeh_tornado) # und sein Websocket bokeh_http.add_sockets(sockets) # Hier wird von Bokeh der Eventloop mit der Bokeh-Instanz un ddem Tornato-Webserver verheiratet server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start()
# To get Gunicorn/Uvicorn's multi-worker # working, we need to create the Bokeh Server # using the low level APIs. Inspired by # https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/flask_gunicorn_embed.py bokeh_app = Application(FunctionHandler(bkapp)) bokeh_tornado = BokehTornado({'/bkapp': bokeh_app}, extra_patterns=[(r'/static_assets/(.*)', StaticFileHandler, {'path': "static"})], extra_websocket_origins=["localhost:8000", "localhost:8001", '%s:8001' % (ip)], ) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_socket(socket) bokeh_server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) bokeh_server.start() from starlette.middleware.cors import CORSMiddleware from starlette.middleware import Middleware # Starlette App creation app = Starlette(debug=True, routes=[ Route('/', endpoint=homepage, name='homepage_url'), Mount('/static', StaticFiles(directory='static'), name='static'), Route('/bokeh', endpoint=redirect_bokeh, name='bokeh_page_url') ] ) ## Only used if running Uvicorn programatically
def bk_worker(): io_loop = IOLoop.current() server = BaseServer(io_loop, bokeh_tornado, bokeh_http) server.start() server.io_loop.start()