And then replicating the flask_gunicorn_embed.py example on github doesn’t work as presumably the line:
sockets, port = bind_sockets(“localhost”, 0)
…sees the server later bound (using bokeh_http.add_sockets(sockets)) to the sockets on localhost (or whatever IP is specified in that field) as opposed to the unix socket?
Can anyone advise whether they’ve been able to embed bokeh in a Flask app where Gunicorn is bound to a socket and note the adjustments they’ve had to make to the flask_gunicorn_embed.py example? I’ve tried specifying mysocket.sock in the bind_sockets call instead but this crashes the app…
Thanks for coming back to me and seasons greetings! I’ve just ended up running a Bokeh server separately and making calls to the server’s IP & port from the Flask app so have managed to embed as required. At the moment in testing and from the docs I can’t see any drawbacks to this other than running Bokeh server and Flask as opposed to just running it all within Flask, would you agree?
The setup you describe – with Flask and bokeh server running as separate applications – is a perfectly reasonable partitioning of functionality.
I deploy my applications to Heroku (an online platform as a service), and because of how it constrains websockets, I found it easiest to organize my code similar to what you describe.
I ended up with a Flask application than handles user management (authentication, access, etc.) and other tasks like using dropzone to upload large-ish datasets.
A bokeh server is running as a separate application (separate Heroku dyno in my case). The Flask app integrates this into its website layout via bokeh’s pull_session(...) and server_session(...) calls.