[Twisted-Python] New to twisted
Fred Hauck
fhauck at srcpsolutions.com
Wed Nov 30 09:20:21 MST 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):
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
More information about the Twisted-Python
mailing list