[Twisted-Python] python crash when running sample code from Twisted Book....

John Case jcase at steuber.com
Thu Dec 22 18:07:07 EST 2005

I am working through the Twisted Network Programming Essentials book by 
Abe Fettig, using python24 and twisted 2.1 on a Win2k sp4 Server 
platform. Python crashes with a memory reference error on 
'reactor.run()' when I run this code (connectiontest.py from Chap 2):

Any suggestions greatly appreciated!!!


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 clientConnectionFailed(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"
      #  sys.exit(1)
    host = 'localhost'
    port = 82
    connecting = testConnect(host, port)
    connecting.addCallback(handleSuccess, port)
    connecting.addErrback(handleFailure, port)

More information about the Twisted-Python mailing list