[pypy-issue] Issue #2614: Differences in buffering of stdin between CPython and PyPy (pypy/pypy)

realead issues-reply at bitbucket.org
Sat Jul 22 16:51:48 EDT 2017

New issue 2614: Differences in buffering of stdin between CPython and PyPy


The man pages of CPython say the following about option `-u`:

-u Force stdin, stdout and stderr to be totally unbuffered. ...  Note that there is internal buffering in xread‐ lines(), readlines() and file-object iterators ("for line in sys.stdin") which is not influenced by this option. 

So if we read from `sys.stdin` with help of file-object iterator, we can see/feel the buffering even if python was called with options `-u`.

However, for pypy we can see, that if started with option `-u` the reading from `sys.stdin`  with help of file-object iterator becomes slower. 

Admittedly,  pypy man pages don't say, that `sys.sdin` stays buffered for `-u`, but this is still a difference from the behavior of CPython.

To reproduce:

First step: create a large input file by running the following script: 


for i in xrange(10**6):
  print 10**9
 via `python create_data.py > input.in`.

Second step: run the following script to see the difference of running times:

import sys
ans = 0    
for line in sys.stdin:
    if int(line)%k == 0:
        ans += 1
with `pypy read_it.py < input.in` and `pypy -u read_it.py < input.in`

More information about the pypy-issue mailing list