def run(): """Run flask application """ log = logging.getLogger(__name__) # get sockets, so bkapp and app can talk bk_sockets, bk_port = get_sockets() # start bokeh sever thread_bokeh = Thread(target=bk_worker, args=[bk_sockets, bk_port], daemon=True) thread_bokeh.start() bokeh_url = BOKEH_URL.replace('$PORT', str(bk_port)) log.info("Bokeh Server App Running at: %s", bokeh_url) # start flask server thread_flask = Thread(target=start_tornado, daemon=True) thread_flask.start() log.info("Flask + Bokeh Server App Running at: %s", FLASK_URL) # loop for ever while True: time.sleep(0.01)
def proxy(path): """ HTTP Proxy """ query = '' if request.query_string is not None: query = '?' + request.query_string.decode("utf-8") bokeh_url = BOKEH_URL.replace('$PORT', get_bokeh_port()) request_url = f"{bokeh_url}/{path}{query}" resp = requests.get(request_url) excluded_headers = ['content-length', 'connection'] headers = [(name, value) for (name, value) in resp.raw.headers.items() if name.lower() not in excluded_headers] response = Response(resp.content, resp.status_code, headers) return response
import logging from threading import Thread from app import start_tornado from bkapp import (bk_worker, get_sockets) from config import (BOKEH_URL, FLASK_URL) logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) # get sockets, so bkapp and app can talk bk_sockets, bk_port = get_sockets() # start bokeh sever t1 = Thread(target=bk_worker, args=[bk_sockets, bk_port], daemon=True) t1.start() bokeh_url = BOKEH_URL.replace('$PORT', str(bk_port)) log.info("Bokeh Server App Running at: %s", bokeh_url) # start flask server t2 = Thread(target=start_tornado, daemon=True) t2.start() log.info("Flask + Bokeh Server App Running at: %s", FLASK_URL) # loop for ever while True: time.sleep(0.05)
_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() if __name__ == '__main__': BK_SOCKETS, BK_PORT = get_sockets() THREAD = Thread(target=bk_worker, args=[BK_SOCKETS, BK_PORT], daemon=True) THREAD.start() BOKEH_URL = BOKEH_URL.replace('$PORT', str(BK_PORT)) LOG.info("Bokeh Server App Running at: %s", BOKEH_URL) while True: time.sleep(0.01)