[Twisted-Python] Guidance on Proxy-type Application

glyph at divmod.com glyph at divmod.com
Fri May 29 09:22:40 MDT 2009


On 08:24 am, michaelnt at gmail.com wrote:
>2009/5/28 <glyph at divmod.com>

>Thanks for the very interesting example which I mainly follow apart 
>from the
>lineReceived method in the ProxyClient, don't we need to add a callback 
>to
>the deferred before appending it to the requestQueue?

Definitely not!  That would defeat the purpose.  The Deferred doesn't 
have a value yet: you're waiting for the other side of the connection to 
respond with an echo line.  As you can see, the result becomes available 
in lineReceived:
>class ProxyClient(LineReceiver):
>    def connectionMade(self):
>        self.requestQueue = []
>
>    def forwardLine(self, line):
>        self.sendLine(line)
>        d = Deferred()
>        self.requestQueue.append(d)
>        return d

And we callback the Deferred when it is available:
>    def lineReceived(self, line):
>        self.requestQueue.pop(0).callback(line)
>
>Thanks, Michael

HTH,

-glyph




More information about the Twisted-Python mailing list