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 xiang.zhang
Recipients xiang.zhang
Date 2015-04-29.02:52:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1430275934.06.0.903599257127.issue24073@psf.upfronthosting.co.za>
In-reply-to
Content
The problem is what the title tells and can be produced by the snippet below.

import sys
import os

sys.stdout.write("%s\n" % sys.stdin.mode)
sys.stdout.flush()
f = os.fdopen(sys.stdin.fileno(), "r")
f.write("aaaa")
f.flush()
f.read()
f.close()

When running this snippet with nohup, which changes the stdin's mode to O_WRONLY(which can also be shown below because the write operation will fail), this snippet will still give sys.stdin.mode as r, both in 2.7 and 3.4.

In 2.7, the os.fdopen will fail with Invalid Argument error because the mode r given to fdopen conflicts with stdin's real mode w. In 3.4, os.fdopen won't give any error.

Both in 2.7 and 3.4, if I change the mode given to os.fdopen to w:
    f = os.fdopen(sys.stdin.fileno(), "w")
The write operation will succeed and the read operation will fail.

The output produced in nohup.out for 2.7 is:
    r
    Traceback (most recent call last):
      File "test.py", line 9, in <module>
        f.read()
    IOError: File not open for reading
For 3.4:
    r
    Traceback (most recent call last):
      File "test.py", line 9, in <module>
        f.read()
    io.UnsupportedOperation: not readable

I run the snippet with nohup on Gnome Terminal, bash, Ubuntu 15.04. The Python version is 2.7.9 and 3.4.3.
History
Date User Action Args
2015-04-29 02:52:14xiang.zhangsetrecipients: + xiang.zhang
2015-04-29 02:52:14xiang.zhangsetmessageid: <1430275934.06.0.903599257127.issue24073@psf.upfronthosting.co.za>
2015-04-29 02:52:13xiang.zhanglinkissue24073 messages
2015-04-29 02:52:13xiang.zhangcreate