def dataReceived(self, data):
    self.transport.write(data)

def connectionMade(self):
    fd = self.f.fileno()
setNonBlocking(fd)
readFromFD(fd, self.dataReceived)

def connectionLost(self, reason):
    self.f.close()

def main(reactor, filename):
    stdio.StandardIO(FileReader(filename))
Non-blocking file access with Twisted