closing a bokeh server via the Lifecycle Hooks


i’m new to bokeh but like it a lot. For a research project I’m working with multiple bokeh servers. I want to close a bokeh server when a session on this server closes (preferably the last session on this server). The server is opened via a subprocess (

import subprocess
import signal
import os
cmd5101 = subprocess.Popen('bokeh serve results --show --args csvPath',shell=False, encoding='utf8')

In this works to close the server:
os.kill(, signal.SIGTERM)

But when adding this via the bokeh Lifecycle Hooks (in happens, the server lives on. I’m not sure on how to pass the server pid correctly to, or if there is another way for closing the server.

          def on_session_destroyed(session_context):
os.kill(, signal.SIGTERM)

My folder structure:

I’m using python 3.6 with spyder IDE but want to add this to a django web project in visual studio 2015.

Any advice is welcome and much appreciated!

Kind regards,