closing a bokeh server via the Lifecycle Hooks

Hi

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 (bokehServercreation.py):


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

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

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

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

My folder structure:
-bokehServerCreation.py
-results
–main.py
–server_lifecycle.py

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,

Joris