For something like this you might want to embed the bokeh server as a library, rather than run it as a separate process:
However, I'm not entirely sure that solves your problem by itself. You could certainly shut down a bokeh server process any time you like (or stop an internal ioloop if you embed it as a library). The question is actually how to determine when the user closes the app window, which is not really a bokeh question, per se, and I am not sure I have an answer. If you are using a recent version of Qt, maybe you could open the app in a Qt web/html widget? Presumably then you can know when the widget is destroyed, or you could have a "close" button, etc. Something that would give you the hook you need to take the action you want to take.
Alternatively, I will say this workflow is not really what was in mind with the Bokeh server. Typically a server would be long-running, capable of serving many sessions over time, including sessions specifically customized with HTML request arguments. You might consdider whether you can structure your app to start the bokeh server only once, at the beginning, and then use the app embed APIs to open pages with appropriately customized sessions (or even different URLs, a Bokeh server can run multiple apps at once).
On Dec 11, 2018, at 10:01, [email protected] wrote:
I have been trying for some time to find a solution which would close the open (for me usually 5006) port once the bokeh html page is closed in we browser.
The reason why I am asking:
I have got an app created by PyQt, which button click opens cmd and run bokeh serve --show myapp, which opens html plot.
However when html is closed port is still opened and if I try to run the PyQt app again it obviously says port in use.
Is there a way to terminate the port bokeh serve opens when html is closed?
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fca3214a-243b-4cc8-9f81-7a02cf8e1e5c%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.