[Twisted-Python] Why don't Connectors use deferreds?

Mike C. Fletcher mcfletch at rogers.com
Thu Sep 9 11:41:29 MDT 2004


Itamar Shtull-Trauring wrote:
...

>There's a utility class for this in twisted.internet.protocol:
>
>deferredOfProtocolInstance =
>ClientCreator(MyProtocol).connectTCP("localhost", 1234)
>
>If this matches your needs I suggest adding an issue to
>twistedmatrix.com/bugs/ about adding this to the client howto and assign
>to hypatia or me.
>  
>
Okay, issue added to the tracker.  Clarification just so no-one else 
needs to spelunk through to answer the question I had:

The return value is a *connected* protocol.  I gather so because it 
looks as though buildProtocol is called by connector.doRead which then 
calls protocol.makeConnection, which in turn calls 
protocol.connectionMade, and the use of callLater( 0, ...) makes the 
callback fire *after* the protocol has had connectionMade called.

There appear to be cases where the callback can be called with a 
protocol that has failed to initialise, that is, if connectionMade (or 
any of the other operations between callback scheduling and execution) 
fails for some reason, the callback will still be called.  As such the 
callback really is just notifying that the connection has gone through 
(more precisely, that the protocol has been built), not necessarily that 
the protocol is fully initialised and ready-to-go.

Still, it does everything I need with a little bit of checking to be 
sure that the initialisation completed.

Thanks,
Mike

________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com





More information about the Twisted-Python mailing list