[Twisted-Python] python crash when running sample code from Twisted Book....
John Case
jcase at steuber.com
Thu Dec 22 16:07:07 MST 2005
Hello!
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):
self.factory.deferred.callback("Connected!")
self.transport.loseConnection()
class ConnectionTestFactory(protocol.ClientFactory):
protocol = CallbackAndDisconnectProtocol
def __init__(self):
self.deferred = defer.Deferred()
def clientConnectionFailed(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 = 'localhost'
port = 82
connecting = testConnect(host, port)
connecting.addCallback(handleSuccess, port)
connecting.addErrback(handleFailure, port)
reactor.run()
More information about the Twisted-Python
mailing list