Moritz Moritz - 9 months ago 186
Python Question

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=", 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
for ending the process. Maybe
would be better. I will try it.


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 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.