How to stop bokeh server?
<p>I do use bokeh to plot sensor data live on the local LAN. Bokeh is started from within my python application using popen: <code>Popen("bokeh serve --host=localhost:5006 --host=192.168.8.100:5006", shell=True)</code></p>

<p>I would like to close bokeh server from within the application. However, I cannot find anything in the <a href="http://bokeh.pydata.org/en/latest/docs/user_guide/cli.html#userguide-cli" rel="nofollow">documentation</a>. Also <code>bokeh serve --help</code> does not give any hint how to do that.</p>

<p>EDIT: based on the accepted answer I came up with following solution:</p>

<pre><code>        self.bokeh_serve = subprocess.Popen(shlex.split(command),
                             shell=False, stdout=subprocess.PIPE)
</code></pre>

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

<p>Without knowing bokeh and assuming that you use Python >= 3.2 or Linux, you could try to kill the process with <code>SIGTERM</code>, <code>SIGINT</code> or <code>SIGHUP</code>, using <a href="https://docs.python.org/3/library/os.html#os.kill" rel="nofollow"><code>os.kill()</code></a> with <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen.pid" rel="nofollow"><code>Popen.pid</code></a> <strong>or even better</strong> <a href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal" rel="nofollow"><code>Popen.send_signal()</code></a>. If bokeh has proper signal handlers, it will even shutdown cleanly.</p>

<p>However, you may be better off using the option <code>shell=False</code>, because with <code>shell=True</code>, the signal is sent to the shell instead of the actual process.</p>

python bokeh