
A thread in a bokeh serve script needs an exit signal to gracefully exit. Stopping bokeh serve from command line with ctrl-C works but the thread hangs, preventing the complete exit.
I typically signal multiple threads via Python Events when KeyboardInterrupt exception is detected, like this:
try:
run_multiple_threads()
except KeyboardInterrupt as err:
e.set() # all threads exit!
sys.exit()
This isn’t working with bokeh serve. It seems that run_until_shutdown() catches the KeyboardInterrupt but returns nothing.
What’s the best way to tell other threads to exit when Bokeh server exits?

