如何停止散景服务器?

Mor*_*itz 7 python bokeh

我确实使用散景来绘制本地 LAN 上的传感器数据。Bokeh 是从我的 python 应用程序中使用 popen 启动的:Popen("bokeh serve --host=localhost:5006 --host=192.168.8.100:5006", shell=True)

我想从应用程序中关闭散景服务器。但是,我在文档中找不到任何内容。也bokeh serve --help没有给出任何提示如何做到这一点。

编辑:基于接受的答案,我想出了以下解决方案:

        self.bokeh_serve = subprocess.Popen(shlex.split(command),
                             shell=False, stdout=subprocess.PIPE)
Run Code Online (Sandbox Code Playgroud)

我用来self.bokeh_serve.kill()结束进程。也许.terminate()会更好。我会尝试。

cod*_*kel 3

在不了解 bokeh 并假设您使用 Python >= 3.2 或 Linux 的情况下,您可以尝试使用SIGTERMSIGINTSIGHUP、 using os.kill()with或什至更好地终止进程。如果散景有适当的信号处理程序,它甚至会干净地关闭。Popen.pid Popen.send_signal()

但是,您可能最好使用该选项shell=False,因为使用该shell=True选项,信号将发送到 shell 而不是实际进程。