All pastes #39136 Raw Edit

Foo

public python v1 · immutable
#39136 ·published 2006-01-30 16:51 UTC
rendered paste body
from twisted.internet import protocol, reactorfrom twisted.protocols import basicimport threading, timeclass TestProto(protocol.Protocol):    def connectionMade(self):        print 'Connected'        self.transport.write('Connection test!\r\n')            def dataReceived(self, data):        print data,    def callIn(self):        print 'callIn'        self.transport.write('callInThread test!\r\n')class TestFactory(protocol.ClientFactory):    protocol = TestProto    def __init__(self):        self.test = TestFactory.protocol()    def buildProtocol(self, addr = None):        return self.testdef main():    reactor.run(installSignalHandlers=0)factory = TestFactory()reactor.connectTCP('localhost', 2005, factory)th1 = threading.Thread(target = main)th1.setDaemon(True)th1.start()while not factory.test.connected:    time.sleep(0.1)reactor.callFromThread(factory.test.callIn)print 'done'reactor.stop()time.sleep(1)