[Twisted-Python] Question about Using Deferreds in ServerProtocol request Handler
Andrew Francis
andrewfr_ice at yahoo.com
Wed Feb 20 08:51:41 MST 2008
Hi Folks:
Much of what I do with Stackless involves making calls
from server requests that in turn, make Twisted calls
that return a deferred.
i.e.,
class MyRequestHandler(http.Request):
"""
let us create a tasklet to do work in the request
handler
and allow the Reactor to continue
"""
def process(self):
t = stackless.tasklet(self.doWork)()
def doWork(self):
message =
MyRequestHandler.processor.getPage("")
self.write(message)
self.finish()
return
I have been able to do the same thing with an
inlineCallback
class MyRequestHandler(http.Request):
@defer.inlineCallbacks
def process(self):
try:
result = yield
client.getPage("http://www.google.com")
except Exception, err:
log.err(err, "process getPage call
failed")
else:
self.setHeader('Content-Type',
'text/html')
self.write(result)
self.finish()
(although this works, the technique is not general for
all protocols)
However, how is this done with just deferreds and
callbacks without Stackless or inlineCallbacks?
Cheers,
Andrew
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
More information about the Twisted-Python
mailing list