[Twisted-Python] New to twisted
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): self.factory.deferred.callback("Connected!") self.transport.loseConnection() class ConnectionTestFactory(protocol.ClientFactory): protocol = CallbackAndDisconnectProtocol def __init__(self): self.deferred = defer.Deferred() def clientConnnectionFailed(self, connector, reason): self.deferred.errback(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 reactor.stop() def handleFailure(failure, port): print "Error connecting to port %i: %s" % (port,failure.getErrorMessage()) reactor.stop() if __name__ == "__main__": import sys if not len( sys.argv) == 3: print "Usage: connectiontest.py host port" sys.exit(1) 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) reactor.run() 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 fred
Fred Hauck wrote:
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.
Hi Fred, connectiontest.py should only report an error if you try to connect to an invalid host, or to a port that isn't open. What happens if you try to connect to an invalid host? python connectiontest.py foo.bar 80 or a closed port? python connectiontest.py fettig.net 81 Proper behavior is an error message, which indictates that the errback fired correctly. Are you seeing something else? I've tested that example on Windows XP, so I don't believe it's a platform issue. Abe
participants (2)
-
Abe Fettig
-
Fred Hauck