[Twisted-web] Shutting down server via web-request with nice status
mszumocki at contman.pl
Wed Feb 23 06:20:01 MST 2005
I have question about how does reactor.stop() work with Nevow.
I have a simple web server (in twisted/nevow) that does something in background, and
there's a page that's supposed to close the server gracefully. I would like the request
to be served this way:
- client sends the request (opens the page in browser)
- he gets half-finished page with something like "Shutting down..."
- server does some possibly time-confusing stuff then sends "Finished" completing the page
- server stops
I'm pretty new to both twisted and nevow, and this is what i've come up so far quickly.
Surprisingly, it works to some extent, as in server does indeed stop, but i'm looking for
a way to make it non-blocking, so other client who connect in the same time would get
alternative page with "server closing down" message.
Rendering this resource will stop the import process if it's running, then save current
state and configuration and gracefully shutdown import server
NAME = 'Terminating server'
docFactory = loaders.stan(
ul(data = directive('execute'), render=directive("sequence"))[
li(pattern='item')[span(render=directive("string")), "... "],
def data_execute(self, context, data):
yield "Stopping import process"
yield "Saving configuration"
yield "Shutting down"
work.terminate() simply calls reactor.stop() at the moment. work.stop() and work.save() are the parts
of blocking code - i intentd to rewrite them to either work in thread or by using deferreds (assuming i manage to
figure out how do deferreds work exactly ;)
Could you please give me some ideas as to how should data_execute method look to achieve effect i want?
More information about the Twisted-web