stopping a cherrypy server over http

后端 未结 2 1737
青春惊慌失措
青春惊慌失措 2021-01-12 23:58

I have a cherrypy app that I\'m controlling over http with a wxpython ui. I want to kill the server when the ui closes, but I don\'t know how to do that. Right now I\'m just

相关标签:
2条回答
  • 2021-01-13 00:14

    How are you stopping CherryPy? By sending a SIGKILL to itself? You should send TERM instead at the least, but even better would be to call cherrypy.engine.exit() (version 3.1+). Both techniques will allow CherryPy to shut down more gracefully, which includes allowing any in-process requests (like your "?sigkill=1" request itself) to finish up and close cleanly.

    0 讨论(0)
  • 2021-01-13 00:26

    I use os._exit. I also put it on a thread, so that I can serve up a "you've quit the server" page before exiting.

    class MyApp(object):
        @cherrypy.expose
        def exit(self):
            """
            /exit
            Quits the application
            """
    
            threading.Timer(1, lambda: os._exit(0)).start()
            return render("exit.html", {})
    
    0 讨论(0)
提交回复
热议问题