Best way to signal other threads to exit upon exiting bokeh server?

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:

except KeyboardInterrupt as err:
    e.set() # all threads 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?

Have you tried marking your threads as daemon?

Hello @p-himik,

Great idea. I had forgotten that option. This works perfectly. Now the thread will exit when Bokeh captures the ctrl+c at the command line.