fork(2) download
  1. import sys
  2. from functools import partial
  3.  
  4. print(sum(chunk.count('\n') for chunk in iter(partial(sys.stdin.read, 1 << 15), '')))
  5.  
Success #stdin #stdout 0.03s 6376KB
stdin
$ pv out.txt | wc -l
  99MB 0:00:00 [ 840MB/s] [=========================================>] 100%            
2055312

$ pv out.txt | python count-lines.py
  99MB 0:00:00 [ 660MB/s] [=========================================>] 100%            
2055312
stdout
7