Title: Bad sys.stdin assignment hangs interpreter.
Type: behavior Stage: resolved
Components: Versions: Python 3.3, Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: flox, pitrou, python-dev, r.david.murray, terry.reedy
Priority: normal Keywords:

Created on 2013-04-28 17:12 by terry.reedy, last changed 2013-04-29 14:23 by python-dev. This issue is now closed.

Messages (4)
msg188006 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-04-28 17:12
This appears to be Python 3 specific. On 2.7.4 (Win7):
>>> import sys
>>> sys.stdin='abd'

With fresh 3.4 repository debug build, prompt never appears, ^C, ^D are ignored. Must close with window's [X] button. With fresh 3.3, get repeated [62312 refs] lines. One could guess that they are generated but suppressed in 3.4.

There is a possibility that this is specific to debug builds; I cannot currently build or run one for 2.7. However, there is no problem with Idle running (on Windows) with 3.3/3.4 pythonw-d. (In other words, see same behavior as 2.7 above.)
msg188026 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-04-28 21:32
Indeed, in both 3.3.0 non-debug and 3.4 tip debug, python starts consuming 100% of the CPU.  I'm guessing there is some subtlety involving the new IO system involved here.

Python 2.7 debug build acts as you indicate for your 2.7 non-debug build.

All my tests are on linux, and I had to kill -HUP the python process.  As you say, ctl-C (and ctl-D, not surprisingly) were ignored.
msg188032 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-04-29 01:41
In searching for an existing issue about this, there seemed to be other edge-case stdin problems. I don't think that they were all usage errors. This problem was revealed by an accidental usage error that should have lain dormant until an exception was raised upon first use by input() (as happened in 2.7).
msg188071 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-29 14:23
New changeset 68d1ac152b5d by Benjamin Peterson in branch '3.3':
ignore errors when trying to fetch sys.stdin.encoding (closes #17863)

New changeset 97522b189c79 by Benjamin Peterson in branch 'default':
merge 3.3 (#17863)
Date User Action Args
2013-04-29 14:23:39python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg188071

resolution: fixed
stage: needs patch -> resolved
2013-04-29 13:12:32floxsetnosy: + flox

title: Bad sys.stdin assignment hands interpreter. -> Bad sys.stdin assignment hangs interpreter.
2013-04-29 01:41:33terry.reedysetmessages: + msg188032
2013-04-28 21:32:34r.david.murraysetnosy: + r.david.murray, pitrou
messages: + msg188026
2013-04-28 17:12:52terry.reedycreate