How do we read a file (non-blocking) and print it to standard output (still not blocking)? This is the easiest way I can think of, but it leaves you feeling that there should be a better way. Something that is undergoing some linear modification of LineReceiver - functionality will be even more preferable.
from twisted.internet import stdio, protocol from twisted.protocols.basic import FileSender from twisted.internet import reactor class FileReader(protocol.Protocol): def connectionMade(self): fl = open('myflie.txt', 'rb') d = FileSender().beginFileTransfer(fl, self.transport) d.addBoth(fl.close) d.addBoth(lambda _: reactor.stop()) stdio.StandardIO(FileReader()) reactor.run()
python asynchronous twisted
neverlastn
source share