Bottle web framework - How to stop?

前端 未结 11 1264
不知归路
不知归路 2020-12-14 06:55

When starting a bottle webserver without a thread or a subprocess, there\'s no problem. To exit the bottle app -> CTRL + c.

In a thread, ho

11条回答
  •  粉色の甜心
    2020-12-14 07:50

    I've found this solution to be the easiest, but it does require that the "psutil" package is installed, to get the current process. It also requires the "signals" module, but that's part of the standard library.

    @route('/shutdown')
    def shutdown():
        current_process = psutil.Process()
        current_process.send_signal(signal.CTRL_C_EVENT)
        return 'Shutting down the web server'
    

    Hope that's of use to someone!

提交回复
热议问题