Title: sys.stdin.readline 'unsupported' (IDLE 2.7.3, Win7, pythonw)
Type: behavior Stage: needs patch
Components: IDLE, Windows Versions: Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: IDLE and Command line present different behavior for sys.stdin
View: 9290
Assigned To: Nosy List: roger.serwy, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2012-10-01 20:01 by terry.reedy, last changed 2012-10-17 00:13 by terry.reedy. This issue is now closed.

Messages (8)
msg171743 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-10-01 20:01
Problem is only 2.7.3 (not 3.2.3, 3.3.0), tested on Windows

Command Line Window
>>> help()
help> _

The _ is blinking, waiting for input.

IDLE Shell
>>> help()
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
  File "C:\Programs\Python27\lib\", line 467, in __call__
    return*args, **kwds)
  File "C:\Programs\Python27\lib\", line 1750, in __call__
  File "C:\Programs\Python27\lib\", line 1762, in interact
    request = self.getline('help> ')
  File "C:\Programs\Python27\lib\", line 1773, in getline
    return raw_input(prompt)
UnsupportedOperation: readline

There is no blinking _, at that is from the raw_input() call that failed. There is no problem with help() in IDLE for 3.2, 3.3.

I see two possibilities:
1. This has nothing to do with Idle directly, but is a problem with pythonw and raw_input/readline that was later fixed.
2. This is a result of how stdin is proxied by Idle and that there is a difference between 2.7 and 3.x.

builtin_raw_input in bltinmodule.c calls
  s = PyOS_Readline(PyFile_AsFile(fin), PyFile_AsFile(fout), prompt);
and I presume PyOS_Readline eventually calls fin.readline()

UnsupportedOperation is defined (in 2.7, at least) in
_pyio._unsupported(self, name) raises it with names.
That in turn is the default body for every operation. In particular,
    def readline(self):

So I presume 2. is the problem and the proxy in the pythonw process is an io subclass that needs readline defined for help() to work.
(Is proxying same on all OSes? Or would problem be Windows only?)
msg171766 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-10-02 01:08
Terry, I am unable to reproduce this error under Win7 Ultimate (no SP1) with either the 32-bit or 64-bit install of 2.7.3. Calling help() produces an interactive prompt in all my test cases. I launched IDLE from the start menu shortcut, with "python.exe -m idlelib.idle", and "pythonw.exe -m idlelib.idle".

Running IDLE without a subprocess doesn't trigger the bug either.

IDLE 2.7.3 works as well on Arch Linux with 2.7.3 (64-bit). 

(Also, I get a blinking vertical bar for the cursor, not an underscore on Win7. This minor detail is likely not relevant, only provided since it is an observed difference.)

Does raw_input() work from a regular python shell for you?
msg173022 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-10-16 09:54
Yes, the first part of my post was about how it worked in regular interactive window: prints text, then prompt, then blinking underline cursor.

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 -- Win7 Professional, with all MS patches.

Are you running the apr 10 release or something compiled later, with the readline stub replaced?

Problem manifests in raw_input(): get same behavior of print prompt then crash when should display input cursor.

>>> raw_input('xyz')  # IDLE still
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
UnsupportedOperation: readline

Problem really is sys.stdin.readline(), which is the dummy stub I quoted in first message.

>>> sys.stdin.readline()

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
UnsupportedOperation: readline
msg173028 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-16 11:26
Check patch for issue9290.
msg173029 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-16 11:28
What type of sys.stdin? Try run in "no subprocess" mode (-n).
msg173044 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-10-16 14:46
I am running 2.7.3 from Apr 10, 2012, freshly installed. I still can not reproduce this problem when running IDLE with or without a subprocess. 

Is your file the original or was it modified by accident? It may be possible that was modified as well and is failing to register stdin correctly.
msg173073 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-10-16 19:10
Roger, you are partially right -- there are changes, but they were intentional. I updated the idlelib part of my installation to match the repository on July 9 to incorporate the _RPCFile wrapping of of the three stdio files, including this:

-        sys.stdin = self.console = self.get_remote_proxy("stdin")

+        sys.stdin = self.console = _RPCFile(self.get_remote_proxy("stdin"))

>>> import sys
>>> sys.stdin
< object at 0x000000000315D320>

Sorry about forgetting this. Anyway, I presume you remember that issue. It seems that there is still a bug either in that update or its interaction with other code. What happens in linux with a fresh 2.7 build?

Serhiy's patch for #9290 replaces _RPCXyxFile with PseudoXyzFile subclasses of revised PseudoFile. If it works, it should fix this issue also.
msg173111 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-10-16 23:36
Terry, your idlelib directory is in an inconsistent state. IDLE 2.7.3 works well on Arch Linux. I rebuilt it from revision 70274d53c1dd. With and without a subprocess, IDLE's sys.stdin.readline works.

Let's close this issue and focus on #9290. It's your decision to close.
Date User Action Args
2012-10-17 00:13:45terry.reedysetstatus: open -> closed
superseder: IDLE and Command line present different behavior for sys.stdin
resolution: duplicate
2012-10-16 23:36:37roger.serwysetmessages: + msg173111
2012-10-16 19:10:04terry.reedysetmessages: + msg173073
2012-10-16 14:46:01roger.serwysetmessages: + msg173044
2012-10-16 11:28:22serhiy.storchakasetmessages: + msg173029
2012-10-16 11:26:37serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg173028
2012-10-16 09:54:23terry.reedysetmessages: + msg173022
title: Help() fails at raw_input readline (IDLE 2.7.3, Win7, pythonw) -> sys.stdin.readline 'unsupported' (IDLE 2.7.3, Win7, pythonw)
2012-10-02 01:08:49roger.serwysetmessages: + msg171766
2012-10-01 20:01:13terry.reedycreate