Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Development HTTP server not stopped when raising SystemExit #100

Closed
hdemers opened this Issue · 3 comments

2 participants

@hdemers

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
Collaborator

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

@hdemers

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 referenced this issue from a commit in Irfy/webpy
@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
Collaborator

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.