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.

classification
Title: IDLE and Command line present different behavior for sys.stdin
Type: behavior Stage: resolved
Components: IDLE, IO Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Geraldo.Xexeo, Jim.Jewett, a, kbk, loewis, python-dev, roger.serwy, serhiy.storchaka, taleinat, terry.reedy
Priority: normal Keywords: needs review, patch

Created on 2010-07-18 01:51 by Geraldo.Xexeo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
idle_stdstreams-3.3.patch serhiy.storchaka, 2012-10-10 17:01 Patch for 3.3 and 3.4 review
idle_stdstreams-3.2.patch serhiy.storchaka, 2012-10-10 17:02 Patch for 3.2 review
idle_stdstreams-2.7.patch serhiy.storchaka, 2012-10-10 17:03 Patch for 2.7 review
Messages (11)
msg110621 - (view) Author: Geraldo Xexeo (Geraldo.Xexeo) Date: 2010-07-18 01:51
The fact that in IDLE sys.stdin is a idlelib.rpc.RPCProxy  results in programs having different behavior in IDLE and in Command Line mode.

I noticed that when grading many students exercises in IDLE. Things like:

sys.stdin.readlines()

just don´t exists in IDLE, but are fully operational in Command Line mode.

In Command Line mode, sys.stdin is a file.

This is expected, as the manual (27.1) says that sys.stdin (and stdout and stderrr) are "File objects corresponding to the interpreter’s standard input"

There are also other "quirks".

I fell that is really strange that stdin has different behavior for the same program.
msg110904 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2010-07-20 14:42
I agree that the wrapping of these in IDLE should be as transparent as possible.

It would be helpful if you could specify what other "quirks" you have found regarding sys.stdin, sys.stdout and sys.stderr, preferably describing use cases where these are problematic.
msg155389 - (view) Author: (a) Date: 2012-03-11 15:49
Other quirks apparently caused by this bug:

msvcrt.getch() does not block and wait for a keypress in IDLE.  Returns immediately with b'\xff'.

Some of the suggested usage in the manual for sys.stdin does not work under IDLE.  E.g. sys.stdin.detach() doesn't work in IDLE.  On this last point, the manual has a caveat in the last line of the sys.stdin description that could exonerate it.  Regardless, the behavior is inconsistent and makes for awkward UI when using IDLE.
msg155951 - (view) Author: Jim Jewett (Jim.Jewett) * (Python triager) Date: 2012-03-15 20:15
msvcrt.getwch has a similar failure, returning (2**16)-1.

Because of this, getpass.win_getpass (used as getpass.getpass on windows) echoes the password when using Idle (even without a subprocess), but does not echo passwords when from a command-line python.
msg172595 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-10 17:00
The proposed patches make the behavior of sys.std* files in IDLE more similar to the behavior of sys.std* files in standard interpreter. Now sys.stdin have read() and readlines() methods. The source code is simplified.
msg172685 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-10-11 19:59
I tried the patch for 3.3 and it works for me on Linux. It correctly handles prior issues like #13532, #15318, #15319, and #7163, as well as providing good support for .read, .readline, .readlines. Each of those methods respond correctly to Ctrl+C and Ctrl+D.

On Windows 7, with 2.7.3, Ctrl+D is still needed to indicate end-of-file, instead of Ctrl+Z. This may or may not be significant, but it is related to issue14735.
msg173072 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-10-16 19:09
I agree with the goal. We need an automated test for these proxies.
msg173084 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-16 19:59
Unfortunately we have not a unittest framework for IDLE yet. After implementing issue15392 I will make tests for these proxies.
msg175744 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-17 14:44
Since all previous changes were dispense with tests, I don't see why it should become an obstacle for this patch.  Please review.  This patch provides a simple and reliable solution for some other issues (mentioned in msg172685 issues and issue12967).
msg179988 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-14 22:47
If no one objects, I'm going to commit this next week.
msg180586 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-01-25 14:15
New changeset def4cd7e0a9f by Serhiy Storchaka in branch '2.7':
Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
http://hg.python.org/cpython/rev/def4cd7e0a9f

New changeset 0d26f3aa7a8f by Serhiy Storchaka in branch '3.2':
Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
http://hg.python.org/cpython/rev/0d26f3aa7a8f

New changeset 9dfbd65d5041 by Serhiy Storchaka in branch '3.3':
Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
http://hg.python.org/cpython/rev/9dfbd65d5041

New changeset 458b36fb12bc by Serhiy Storchaka in branch 'default':
Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
http://hg.python.org/cpython/rev/458b36fb12bc
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53536
2013-01-25 18:13:17serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-01-25 14:15:05python-devsetnosy: + python-dev
messages: + msg180586
2013-01-14 22:47:49serhiy.storchakasetmessages: + msg179988
2012-12-27 20:49:31serhiy.storchakasetassignee: serhiy.storchaka
2012-11-17 14:44:04serhiy.storchakasetkeywords: + needs review
type: behavior
messages: + msg175744
2012-11-17 14:39:17serhiy.storchakalinkissue12967 superseder
2012-10-24 09:20:54serhiy.storchakasetstage: patch review
2012-10-17 00:13:45terry.reedylinkissue16103 superseder
2012-10-16 19:59:01serhiy.storchakasetmessages: + msg173084
2012-10-16 19:09:41terry.reedysetnosy: + terry.reedy
messages: + msg173072
2012-10-11 19:59:39roger.serwysetnosy: + roger.serwy
messages: + msg172685
2012-10-10 17:03:16serhiy.storchakasetfiles: + idle_stdstreams-2.7.patch
2012-10-10 17:02:29serhiy.storchakasetfiles: + idle_stdstreams-3.2.patch
2012-10-10 17:01:06serhiy.storchakasetfiles: + idle_stdstreams-3.3.patch
keywords: + patch
2012-10-10 17:00:19serhiy.storchakasetnosy: + loewis, kbk, serhiy.storchaka

messages: + msg172595
versions: + Python 2.7, Python 3.3, Python 3.4
2012-03-15 20:15:12Jim.Jewettsetnosy: + Jim.Jewett
messages: + msg155951
2012-03-11 15:49:16asetnosy: + a

messages: + msg155389
versions: + Python 3.2, - Python 3.1
2010-07-20 14:42:59taleinatsetnosy: + taleinat
messages: + msg110904
2010-07-18 01:51:33Geraldo.Xexeocreate