[Web-SIG] Async API - example of my implementation
Peter Hunt
floydophone at gmail.com
Sat Oct 16 04:16:11 CEST 2004
I'm working on getting subversion running again, but for now, take a
look at how I write my Twisted WSGI async apps.
def blocking_call():
d = defer.Deferred()
reactor.callLater(2, d.callback, None)
return d
def phase2(result, environ):
environ["thetime"] = time.time()
environ["twisted.wsgi.resume"]()
def blocking_async_app(environ, start_response):
write = start_response("200 OK", [("Content-type","text/plain")])
yield "the time right now is " + `time.time()` + "\n"
blocking_call().addCallback(phase2, environ)
yield ""
yield "the time now is " + `environ["thetime"]`
Is this acceptible?
Basically, when in the special async mode, the gateway iterates over
the application iterator until it hits a "". It then lets the app do
its thing until environ["twisted.wsgi.resume"]() is called, at which
point it repeats this process until StopIteration.
What do you think?
More information about the Web-SIG
mailing list