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(): 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(): 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(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(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 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 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(): 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()
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 base(score_title): LOGGER.info("you're on {}".format(score_title)) url = '/' + score_title score = APPS[score_title](score_title) LOGGER.info("starting score...") score() LOGGER.info("starting server...") bokeh_tornado = BokehTornado({url: score.app}, extra_websocket_origins=["localhost:8000"]) # extra_websocket_origins=["52.53.126.244:8000"]) # A non-blocking, single-threaded HTTP server (from Tornado) bokeh_http = HTTPServer(bokeh_tornado) # If port is 0, the OS automatically chooses a free port # sockets will listen to localhost # Opens a new process (visible with netstat) on the port sockets, port = bind_sockets('127.0.0.1', 0) # sockets, port = bind_sockets('0.0.0.0', 0) bokeh_http.add_sockets(sockets) LOGGER.info("sockets, port: {}, {}".format(sockets, port)) 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() LOGGER.info("starting thread...") Thread(target=bk_worker).start() script = server_document('http://localhost:{}{}'.format(port, url)) # script = server_document('http://52.53.126.244:{}{}'.format(port, url)) return render_template("base.html", script=script, title=score_title)
"bokeh_page_url": "http://%s:%s" % (request.url.hostname, 8001), "rendered_by_bokeh_server": False} ) # Bokeh Server configuration and startup: # # 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'),
async def server_status(request): return JSONResponse({"status": "OK"}) # Bokeh Server configuration and startup: # # 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:%s" % os.environ["BOKEH_SERVER_PORT"]]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_socket(socket) bokeh_server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) bokeh_server.start() # Starlette App creation app = Starlette(debug=True, routes=[ Route('/', endpoint=homepage, name='homepage_url'), Mount('/static', StaticFiles(directory='static'),
current_dataset = current_dataset, theme = theme, rightdiv = rightdiv, center = center ) @app.route("/craft", methods=['GET']) def craft_get(): craft_data = "".join(craft_temp % (company, state, barrels2008, barrels2009, barrels2010, barrels2011, barrels2012, barrels2013, barrels2014, barrels2015, barrels2016, barrels2017, barrels2018) for company, state, barrels2008, barrels2009, barrels2010, barrels2011, barrels2012, barrels2013, barrels2014, barrels2015, barrels2016, barrels2017, barrels2018 in get_data(query_craft)) return render_template("craft.html", craft_data=craft_data) @app.route("/states", methods=['GET']) def states_get(): state_data = "".join(state_temp % (state, barrels2008, barrels2009, barrels2010, barrels2011, barrels2012, barrels2013, barrels2014, barrels2015, barrels2016, barrels2017, barrels2018) for state, barrels2008, barrels2009, barrels2010, barrels2011, barrels2012, barrels2013, barrels2014, barrels2015, barrels2016, barrels2017, barrels2018 in dframe()) return render_template("states.html", state_data=state_data) def bk_worker(): asyncio.set_event_loop(asyncio.new_event_loop()) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=[ "157.245.12.139"]) bokeh_http = HTTPServer(bokeh_tornado) bokeh_http.add_sockets(sockets) server = BaseServer(IOLoop.current(), bokeh_tornado, bokeh_http) server.start() server.io_loop.start() from threading import Thread Thread(target=bk_worker).start()
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") bkapp = Application(FunctionHandler(modify_doc)) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["localhost:8000"]) bokeh_http = HTTPServer(bokeh_tornado) # This is so that if this app is run using something like "gunicorn -w 4" then # each process will listen on its own port sockets, port = bind_sockets("localhost", 0) bokeh_http.add_sockets(sockets) @app.route('/', methods=['GET']) def bkapp_page(): script = server_document('http://localhost:%d/bkapp' % port) return render_template("embed.html", script=script, template="Flask") def bk_worker():
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") bkapp = Application(FunctionHandler(modify_doc)) bokeh_tornado = BokehTornado({'/bkapp': bkapp}, extra_websocket_origins=["127.0.0.1:8000"]) bokeh_http = HTTPServer(bokeh_tornado) # This is so that if this app is run using something like "gunicorn -w 4" then # each process will listen on its own port sockets, port = bind_sockets("127.0.0.1", 46518) bokeh_http.add_sockets(sockets) @app.route('/', methods=['GET']) def bkapp_page(): print('here') script = server_document('http://127.0.0.1:%d/bkapp' % port) print(str(script)) return render_template("embed.html", script=script, template="Flask")