[Twisted-Python] Guidance on Proxy-type Application

Michael Thompson michaelnt at gmail.com
Fri May 29 02:24:45 MDT 2009


2009/5/28 <glyph at divmod.com>

>
> On 01:23 am, asb.bush at gmail.com wrote:
>
>> I have just started to look at the Twisted framework and would like to put
>> it
>> to use for a new project I am working on.  Not being very familiar with
>> the
>> framework and fairly new to Python in general I would like to ask a
>> design/architecture question.  (I have written similar applications in C
>> but
>> would prefer to start this in the right direction and not write Python
>> like
>> C.)
>>
>
> Thanks for asking!
>
> I apologize for the delay in my answer.  I started writing up a simple
> example (attached) but was discouraged to find that it was 100 lines long
> and required too much explaining.
>
> Then I started documenting it and explaining every line but that was a very
> long, tedious message.  So, it doesn't have much in the way of explanation;
> I hope you will find it useful regardless.


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?

class ProxyClient(LineReceiver):
    def connectionMade(self):
        self.requestQueue = []

    def forwardLine(self, line):
        self.sendLine(line)
        d = Deferred()
        self.requestQueue.append(d)
        return d

    def lineReceived(self, line):
        self.requestQueue.pop(0).callback(line)

Thanks, Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20090529/b2231724/attachment.html>


More information about the Twisted-Python mailing list