Development HTTP server not stopped when raising SystemExit #100

Closed
hdemers opened this Issue Sep 23, 2011 · 3 comments

Projects

None yet

2 participants

@hdemers
hdemers commented Sep 23, 2011

In file httpserver.py, function runsimple, the exception SystemExit is not caught alongside KeyboardInterrupt. By catching SystemExit, the dev server would behave more like the production server.

@anandology
Contributor

Do you mean calling server.stop() so that it can close all the open sockets etc?

@hdemers
hdemers commented Oct 21, 2011

Well, server.stop() is already called on line 154 of file httpserver.py.

However, SystemExit is not caught alongside KeyboardInterrupt on line 153. It would be good to catch that exception there, so the server is stopped when sys.exit is called.

@Irfy Irfy added a commit to Irfy/webpy that referenced this issue Dec 16, 2011
@Irfy Irfy Make web.py applications stoppable in stand-alone mode
web.py applications typically run in WSGI mode, but when used in embedded
environments, it may be more useful to run the application in stand-alone
server mode (a.k.a. 'app.run()').

Also, running the application via 'app.run()' in a different thread kills
the out-of-the-box behavior of stopping the application with Ctrl-C.

This patch adds the 'stop(self)' method to the application class, so that
applications running stand-alone can be stopped easily with 'app.stop()'.

Credits: llc at stackoverflow: http://stackoverflow.com/questions/5389111

Related to: #100
23d24d8
@anandology
Contributor

sys.exit is working now. I think it is good enough.

Here is an example with /shutdown.

import web
import sys

urls = (
    "/", "hello",
    "/shutdown", "shutdown",
)
app = web.application(urls, globals())

class hello:
    def GET(self):
        return "hello word"


class shutdown:
    def GET(self):
        sys.exit(0)

if __name__ == "__main__":
    app.run()
@anandology anandology closed this May 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment