[Twisted-Python] StandardIO flush'n

Ben Hyde bhyde at pobox.com
Sat Mar 7 13:18:54 EST 2009


I'm new to this, but can somebody explain this behavior to me?  Thanks!

bash-3.2$ (echo a; echo b; sleep 1; echo c) | /tmp/bar.py
line: a
line: b
a
b
line: c
c
bash-3.2$ (echo a; echo b; echo c) | /tmp/bar.py
line: a
line: b
line: c
bash-3.2$ cat /tmp/bar.py
#!/usr/bin/env python
from twisted.internet import reactor
from twisted.protocols.basic import LineOnlyReceiver
from twisted.internet.stdio import StandardIO

class MyLineOnlyReceiver(LineOnlyReceiver):
     delimiter = '\n'
     def lineReceived(self, line):
         self.transport.write(line+self.delimiter)
         print "line:", line
     def connectionLost(self, why):
         LineOnlyReceiver.connectionLost(self, why)
         reactor.callWhenRunning(lambda:reactor.stop())

if __name__ == '__main__':
     StandardIO(MyLineOnlyReceiver())
     reactor.run()
bash-3.2$ port info 'py25-twisted'
py25-twisted @8.0.1 (python, devel, net)

Twisted is an event-driven networking framework written in Python.  
Twisted supports TCP,
UDP, SSL/TLS, multicast, Unix sockets, a large number of protocols  
(including HTTP, NNTP,
SSH, IRC, FTP, and others), and much more.
Homepage:    http://www.twistedmatrix.com/

Library Dependencies: python25, py25-zopeinterface
Maintainers:          stechert at macports.org akitada at macports.org
                       openmaintainer at macports.org
bash-3.2$ python -V
Python 2.5.4
bash-3.2$ uname -a
Darwin d72.cozy.org 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24  
17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 i386
bash-3.2$




More information about the Twisted-Python mailing list