You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IDLE and Command line present different behavior for sys.stdin #53536
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/serhiy-storchaka'closed_at=<Date2013-01-25.18:13:17.248>created_at=<Date2010-07-18.01:51:33.535>labels= ['expert-IDLE', 'type-bug', 'expert-IO']
title='IDLE and Command line present different behavior for sys.stdin'updated_at=<Date2013-01-25.18:13:17.247>user='https://bugs.python.org/GeraldoXexeo'
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.
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.
a commented on Mar 11, 2012
amannequin
Mannequin
More actions
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.
jimjjewett commented on Mar 15, 2012
jimjjewettmannequin
Mannequin
More actions
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.
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.
serwy commented on Oct 11, 2012
serwymannequin
Mannequin
More actions
I tried the patch for 3.3 and it works for me on Linux. It correctly handles prior issues like bpo-13532, bpo-15318, bpo-15319, and bpo-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 bpo-14735.
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 bpo-12967).
Activity
GeraldoXexeo commentedon Jul 18, 2010
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:
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.
taleinat commentedon Jul 20, 2010
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.
a commentedon Mar 11, 2012
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.
jimjjewett commentedon Mar 15, 2012
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.
serhiy-storchaka commentedon Oct 10, 2012
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.
serwy commentedon Oct 11, 2012
I tried the patch for 3.3 and it works for me on Linux. It correctly handles prior issues like bpo-13532, bpo-15318, bpo-15319, and bpo-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 bpo-14735.
terryjreedy commentedon Oct 16, 2012
I agree with the goal. We need an automated test for these proxies.
serhiy-storchaka commentedon Oct 16, 2012
Unfortunately we have not a unittest framework for IDLE yet. After implementing bpo-15392 I will make tests for these proxies.
serhiy-storchaka commentedon Nov 17, 2012
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 bpo-12967).
serhiy-storchaka commentedon Jan 14, 2013
If no one objects, I'm going to commit this next week.
python-dev commentedon Jan 25, 2013
New changeset def4cd7e0a9f by Serhiy Storchaka in branch '2.7':
Issue bpo-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 bpo-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 bpo-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 bpo-9290: In IDLE the sys.std* streams now implement io.TextIOBase
http://hg.python.org/cpython/rev/458b36fb12bc