Hi Jean-Paul:
>However, how is this done with just deferreds and
>callbacks without Stackless or inlineCallbacks?
Thanks for the response. And thanks for the
explanation of inlineCallbacks. Annotating your
example, I get the following:
def process(self):
def callback(result):
print "second"
self.setHeader('Content-Type',
'text/html')
self.write(result)
self.finish()
def errback(err):
err.trap(Exception)
log.err(err, "process getPage call
failed")
try:
d =
client.getPage("http://www.google.com")
except Exception:
d = failure.Failure()
d.addCallbacks(callback, errback)
print "first"
running this I get what I expected
"first"
"second"
This example I can follow. The server protocol handler
terminates. The callback eventually fires. Since the
callback has a reference to the request, it can write
back the response.
Bear with me, I am just starting to read up on
protocols...
What I am unclear on, is why some Server Protocols
depend on 'return' and others don't (I assume with
HTTP, you can stream a response). What is the right
way to design a ServerProtocol? Is there an
'inclineCallback' friendly protocol
Unless I am fundamentally missing something it seems
that there are advantages to designing a Server
Protocol not to depend on 'return'
As I alluded to in other posts, I get confused over
this variation.
This is pyAMF
class pyAMFTest(TwistedGateway):
def __init__(self):
super(TubeTest, self).__init__()
return
def echo(self, x):
print x
return x
pretend I wish to do a callRemote(...)
def echo(self, x):
def callback(result):
print "second"
"""
How do I return x?
"""
def errback(err):
err.trap(Exception)
log.err(err, "process getPage call failed")
try:
proxy = ....
d = proxy.callRemote(...)
except Exception:
d = failure.Failure()
d.addCallbacks(callback, errback)
print "first"
In this case, how is 'x' transmitted back to the
reactor and the client? What is the proper way of
structuring this code.
By the way, the inlineCallback and the Stackless
versions also have problems handling this.
This is starting to stimulate my interest in writing a
Stackless solution that handles this case....
Cheers,
Andrew
____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping