Stop embeded bokeh server when there are no active sessions

Thanks for the input, Bryan.
To answer your question, I have a custom library built on top of bokeh that addresses some specific needs.

In this library each “Plot” object abstracts the Bokeh doc creation, creating a unique Bokeh doc for a set of inputs (that includes all the data we need to plot). Because of this I cannot just serve the same Bokeh doc again when I get a new GET request with a different set of data; I need to create a new Bokeh server to serve the new doc.

On top of this I want to be able to serve to different users from the same machine, and release the resources when they are not using it anymore (this service will be running continuously). In this case I was using a single port to illustrate the issue, but the idea is to have a set of ports assigned to this service .

So it’s almost like I’m trying to rebuild a Bokeh server server? :sweat_smile:

I was afraid this wasn’t the intended usage. I like the idea of using sub processes instead, I’m going to experiment with it.