[Twisted-Python] Using deferreds when writing across unreliable network

John Aherne johnaherne at rocs.co.uk
Fri Oct 10 08:48:21 EDT 2008

I think so -- you wont be told when the actual bytes have been pushed
onto the network, nor when they have arrived succesfully at their
destination. You have to add such logic yourself, maybe by having the
recepient send back a confirmation.

So one way to structure this is to let the code that calls
transport.write return a Deferred, call it d. Before returning it, the
code stores d in a well-known place, something like

 d = Deferred()
 outstanding requests[some_id] = d
 return d

The code that handles incoming data will then have to recognize the
confirmation and will invoke the callback method on d:

 def dataReceived(self, data):
     id, payload = unpack(data)
     d = outstanding_requests[id]

This is sort of how my code works in the VIFF project.

> By the way I did find your example, but I could not reconcile why
> some deferred examples had 'automatic' callbacks and other fired
> their own.

That is because of the different ways they are used: Defered is the
basic building block, but DeferredList combines several Deferreds into


Thankyou very much for your replies.

I have a feeling that I now know what I am doing or going to do.

I also think your min-deferred example will be very useful.

Thanks once again.

John Aherne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20081010/71c0f76d/attachment.htm 

More information about the Twisted-Python mailing list