Stopping the cherry server via http

I have a cherry application that I control through http using wxpython ui. I want to kill the server when ui closes, but I do not know how to do it. Right now I'm just doing sys.exit () in a window close event, but as a result

Traceback (most recent call last): File "ui.py", line 67, in exitevent urllib.urlopen("http://"+server+"/?sigkill=1") File "c:\python26\lib\urllib.py", line 87, in urlopen return opener.open(url) File "c:\python26\lib\urllib.py", line 206, in open return getattr(self, name)(url) File "c:\python26\lib\urllib.py", line 354, in open_http 'got a bad status line', None) IOError: ('http protocol error', 0, 'got a bad status line', None) 

is that I do not stop the cherry right?

+6
python cherrypy
source share
2 answers

How do you stop CherryPy? Sending SIGKILL to yourself? You should send TERM instead, at least, but it would be even better to call cherrypy.engine.exit() (version 3.1+). Both methods will allow CherryPy to disconnect more elegantly, which allows you to allow any incoming requests (for example, your request "sigkill = 1") to finish and close cleanly.

+7
source

I am using os._exit. I also put it in a stream so that before I exit, I can serve the "You left the server" page.

 class MyApp(object): @cherrypy.expose def exit(self): """ /exit Quits the application """ threading.Timer(1, lambda: os._exit(0)).start() return render("exit.html", {}) 
+3
source

All Articles