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

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

> I have no concrete solution to what you describe, but I can try and
> explain how Deferreds work.
> The crucial thing is that "someone" or "something" must call the
> callback method on your Deferred. The general rule to follow is that
> it is the code that creates a Deferrred which has the reponsibility of
> calling the callback method at the correct time.
> So when you use the getPage function you get a Deferred back. Behind
> the scenes the getPage function has setup things in such a way that
> the callback method of the returned Deferred is called when the page
> has arrived -- you must not invole callback yourself in this case.
> But if you create a Deferred yourself, then it is up to you to make a
> call to the callback method when ready.
> I hope this helps a bit -- it helped me to look at the implementation
> in defer.py and see that it was less scary than I had imagined :-)
> --
> Martin Geisler


Thanks for the reply.

That does clarify that I need to fire off my own deferreds.

The problem it leaves me at the moment is:

How do I tell when my transport.write has completed. The ACKs for my
messages happen at the TCP level. Does this mean that for writes and reads I
have to work at the application level to register when the write has been
successful and fire my callback then.

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.

Yes. I have looked through the defer.py code to see what was going on. It is
certainly well laid out and easy to follow - just the basic concept needed
clearing up.


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

More information about the Twisted-Python mailing list