Streaming pipes in Python -
i'm trying convert output of vmstat csv file using python, use convert csv , add date , time coloumns:
vmstat 5 | python myscript.py >> vmstat.log
the problem i'm having blocks while trying iterate sys.stdin. seems input buffer doesn't flushed. don't want endlessly loop around , burn processor time i'm trying measure this. here's simple demonstration blocks on line 3:
import sys line in sys.stdin: sys.stdout.write(line) sys.stdout.flush()
is there easy way access stream grep does, without pausing while input buffer fills up?
vmstat 5,does not close stdout, python buffer still waiting more data.
use instead:
for line in iter(sys.stdin.readline, ""): print line
Comments
Post a Comment