[Twisted-Python] timeout and retries

Andrew Bennetts andrew-twisted at puzzling.org
Sat Jun 18 06:34:49 EDT 2005


On Fri, Jun 17, 2005 at 04:41:17PM +0200, Stefano Canepa wrote:
> The following code is a try to write a protocol with timeout and
> retries. The connectioMade is used only as a test. I have some problems:
> 1) even if I placed "\x01" as delimiter the line is sent not terminated
[...]
>     def sendLine(self, msg):
>         """
>         Add <SB> (\x01 i.e. SOH) at the start of message as required by
>         HL7 standard and send the message
>         """
>         msgToSend = "\x01"+msg
>         print msgToSend
>         self.transport.write(msgToSend)
>         print "written"

You've overridden LineReceiver's sendLine to ignore the delimiter attribute.

> 2) even if timeout expired 3 times the success callback is called
[...]
>         d = defer.Deferred() 
>         d.addErrback(self.tooManyRetries)
>         d.addCallback(self.success)

Read the description of how callback/errback chains work again:

    http://twistedmatrix.com/projects/core/documentation/howto/defer.html#auto2

You probably meant:

        d = defer.Deferred() 
        d.addCallbacks(self.success, self.tooManyRetries)

Which has a subtly different meaning.

-Andrew.





More information about the Twisted-Python mailing list