[Twisted-Python] New to twisted

Fred Hauck fhauck at srcpsolutions.com
Wed Nov 30 11:20:21 EST 2005

I am not only new to twisted, but to python as well.

I need what twisted does, so went out and got the "twisted" book
by abe fettig. I am coding each example in the book as i get there.

the connectiontest.py example on page 16 gives me a call back on success,
but not on error.

from twisted.internet import reactor,defer, protocol

class CallbackAndDisconnectProtocol(protocol.Protocol):
  def connectionMade(self):

class ConnectionTestFactory(protocol.ClientFactory):
  protocol = CallbackAndDisconnectProtocol

  def __init__(self):
    self.deferred = defer.Deferred()

  def clientConnnectionFailed(self, connector, reason):

def testConnect(host, port):
  testFactory = ConnectionTestFactory()
  reactor.connectTCP(host, port, testFactory)
  return testFactory.deferred

def handleSuccess( result,port):
  print "Connected to port %i" % port

def handleFailure(failure, port):
  print "Error connecting to port %i: %s" % (port,failure.getErrorMessage())

if __name__ == "__main__":
  import sys
  if not len( sys.argv) == 3:
     print "Usage: connectiontest.py host port"

  host = sys.argv[1]
  port = int(sys.argv[2])
  connecting = testConnect(host, port)
#  connecting.addCallback( handleSuccess, port)
#  connecting.addErrback( handleFailure,port)
  connecting.addBoth( handleFailure,port)

The environment is:

Windows XP sp2
python 2.4.1 from activestate
twisted_nodocs-2.1.0.win32-py24.exe (installed)

When chasing this down, go into the main loop and there are
comments about "signals" not working in windows, etc. etc.

CallLater works fine, successful callback works fine, the errback
does not

thanks in advance

More information about the Twisted-Python mailing list