Q:

How to stop bokeh server?

I do use bokeh to plot sensor data live on the local LAN. Bokeh is started from within my python application using popen: Popen("bokeh serve --host=localhost:5006 --host=192.168.8.100:5006", shell=True)
I would like to close bokeh server from within the application. However, I cannot find anything in the documentation. Also bokeh serve --help does not give any hint how to do that.
EDIT: based on the accepted answer I came up with following solution:
        self.bokeh_serve = subprocess.Popen(shlex.split(command),
                             shell=False, stdout=subprocess.PIPE)

I used self.bokeh_serve.kill() for ending the process. Maybe .terminate() would be better. I will try it.

A:

Without knowing bokeh and assuming that you use Python >= 3.2 or Linux, you could try to kill the process with SIGTERM, SIGINT or SIGHUP, using os.kill() with Popen.pid or even better Popen.send_signal(). If bokeh has proper signal handlers, it will even shutdown cleanly.
However, you may be better off using the option shell=False, because with shell=True, the signal is sent to the shell instead of the actual process.

