a guest Apr 18th, 2016 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- class PoetryProtocol(Protocol):
- poem = ''
- task_num = 0
- def makeConnection(self, transport):
- Protocol.makeConnection(self, transport)
- from twisted.internet import reactor
- self.timeout = reactor.callLater(20, self.transport.loseConnection)
- def dataReceived(self, data):
- self.poem += data
- msg = 'Task %d: got %d bytes of poetry from %s'
- print msg % (self.task_num, len(data), self.transport.getPeer())
- def connectionLost(self, reason):
- if self.timeout.called is not 1:
- def poemReceived(self, poem):
- self.factory.poem_finished(self.task_num, poem)
RAW Paste Data