crash when reading non-blocking subprocess output

Create issue
Issue #3042 resolved
Jacob Lifshay created an issue

Output:

RPython traceback:
  File "pypy_interpreter.c", line 37926, in BuiltinCode_funcrun_obj
  File "pypy_module__io_1.c", line 11207, in W_BufferedReader_readline_w
  File "implement_2.c", line 32105, in dispatcher_70
  File "pypy_module__io.c", line 15998, in W_BufferedReader__raw_read
Traceback (most recent call last):
  File "pypy_bug.py", line 10, in <module>
    s = p.stdout.readline()
SystemError: unexpected internal exception (please report a bug): <BlockingIOError object at 0x7f9481569f00>; internal traceback was dumped to stderr

Versions:
Python 3.6.1 (7a2e437acfce, Mar 21 2019, 13:39:41)
[PyPy 7.2.0-beta0 with GCC 6.2.0 20160901]
Ubuntu 18.04 x86_64

reproducable using:

import subprocess
import fcntl
import os
from select import select

p = subprocess.Popen(["/bin/bash", "-c", "printf ''"], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=None)
fl = fcntl.fcntl(p.stdout, fcntl.F_GETFL)
fcntl.fcntl(p.stdout, fcntl.F_SETFL, fl | os.O_NONBLOCK)
while True:
    s = p.stdout.readline()
    print(s)
    if len(s) == 0:
        if p.poll() is not None:
            break
        try:
            select([p.stdout], [], [], 1.0)
        except InterruptedError:
            pass

Comments (3)

  1. Armin Rigo

    Reduced to:

    import fcntl
    import os
    
    fdin, fdout = os.pipe()
    f = os.fdopen(fdin, "rb")
    fl = fcntl.fcntl(f, fcntl.F_GETFL)
    fcntl.fcntl(f, fcntl.F_SETFL, fl | os.O_NONBLOCK)
    s = f.readline()    # <= crashes here
    print(repr(s))
    
  2. Log in to comment