This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients ivank, neologix, pitrou, python-dev, vstinner
Date 2014-11-12.20:53:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1415825613.73.0.608402450385.issue21090@psf.upfronthosting.co.za>
In-reply-to
Content
On IRC, buck1 asked why the following code behaves differently on Python < 3.4 and Python >= 3.4. It is related to this issue in fact.

Code:
---
from __future__ import print_function

from os import openpty
read, write = openpty()

from subprocess import Popen
proc = Popen(
    ('echo', 'ok'),
    stdout=write,
    close_fds=True,
)

from os import fdopen
fdopen(write, 'w').close()
with fdopen(read) as stdout:
    print('STDOUT', stdout.read())

print('exit code:', proc.wait())
---

Simplified example:
---
import io, os
read, write = os.openpty()
os.write(write, b'ok\n')
os.close(write)
with io.FileIO(read, closefd=False) as fp:
    print(fp.readall())
---

On Python < 3.4, it displays "ok", whereas Python 3.4 and later fail with 
OSError(5, 'Input/output error' on readall().

Another example:
---
import os
read, write = os.openpty()
os.write(write, b'ok\n')
os.close(write)
print("read: %r" % os.read(read, 4096))
print("read: %r" % os.read(read, 4096))
---

The first read syscall succeed, even if the write end is already called. But the second read syscall fails with EIO.
History
Date User Action Args
2014-11-12 20:53:33vstinnersetrecipients: + vstinner, pitrou, ivank, neologix, python-dev
2014-11-12 20:53:33vstinnersetmessageid: <1415825613.73.0.608402450385.issue21090@psf.upfronthosting.co.za>
2014-11-12 20:53:33vstinnerlinkissue21090 messages
2014-11-12 20:53:33vstinnercreate