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
PyOS_StdioReadline is printing the prompt on stderr #57078
bpo-1927: Change input() to always prompt to stderr
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=Noneclosed_at=<Date2016-01-19.02:50:54.156>created_at=<Date2011-08-31.14:38:37.918>labels= ['interpreter-core', 'type-bug']
title='PyOS_StdioReadline is printing the prompt on stderr'updated_at=<Date2016-01-19.02:50:54.144>user='https://github.com/albertz'
The startup messages are written to standard error.
The interactive interpreter prompts to the original standard error if Readline not used. But with Gnu Readline, prompts do go to the original standard output, as does other interactive Readline output (echoed input etc). This is what Albert reported.
The interactive interpreter always reads from the original standard input, whether Readline is used or not.
The displayhook() function always writes to the current sys.stdout, as documented.
The excepthook() function always writes to the current sys.stderr, also as documented.
The input() function is documented to prompt to sys.stdout, however see bpo-1927 for some quirks with that.
The input() function always reads from the current sys.stdin. The Readline library is only used if sys.stdin and sys.stdout are the original file descriptors.
I agree it would probably be more consistent for the interpreter prompt to go to standard output. It looks like stdout is inspected to determine whether Readline will be used, while stderr is not inspected. So it makes sense for the prompt to go to stdout.
However I disagree that it should go to a redirected stream, sys.stderr or sys.stdout, since sys.stdin does not affect input. But see bpo-17620, about redirecting sys.stdin.
Actually bpo-1927 has a simple patch which should change this to stdout. I haven’t tested, the code looks like that patch will not use a redirected sys.stdout, so it would match not using a redirected sys.stdin.
Drekin commented on Nov 22, 2015
Drekinmannequin
Mannequin
More actions
The interactive interpreter always reads from the original standard input, whether Readline is used or not.
This is not true – the interactive interpreter reads via PyOS_Readline, which may call whatever readline hook is installed.
Adam: My experiments were assuming that PyOS_Readline() only ever uses the basic implementation or the Readline library, in order to see if there was any consistency with how Python worked in common situations.
There is actually a test that waits for the interpreter prompt on stderr; see test_cmd_line_script.CmdLineTest.interactive_python(). I realized that changing this would have to be considered carefully, because it could easily break other code as well. It certainly should not be done in a bug fix release.
Anyway I am proposing a patch in bpo-1927 to fix PyOS_StdioReadline(), so closing this as a duplicate.
Activity
albertz commentedon Aug 31, 2011
PyOS_StdioReadline from Parser/myreadline.c is printing the prompt on stderr.
I think it should print it on the given parameter sys_stdout. Other readline implementations (like from the readline module) also behave this way.
Even if it really is supposed to write on stderr, it should use the
sys.stderrand not the system stderr.Drekin commentedon Aug 25, 2013
Related stackoverflow question: http://stackoverflow.com/questions/18419787/where-does-pythons-interactive-prompt-output-to .
vadmium commentedon Aug 4, 2015
Results of experimenting on 3.6:
I agree it would probably be more consistent for the interpreter prompt to go to standard output. It looks like stdout is inspected to determine whether Readline will be used, while stderr is not inspected. So it makes sense for the prompt to go to stdout.
However I disagree that it should go to a redirected stream, sys.stderr or sys.stdout, since sys.stdin does not affect input. But see bpo-17620, about redirecting sys.stdin.
vadmium commentedon Nov 22, 2015
Actually bpo-1927 has a simple patch which should change this to stdout. I haven’t tested, the code looks like that patch will not use a redirected sys.stdout, so it would match not using a redirected sys.stdin.
Drekin commentedon Nov 22, 2015
This is not true – the interactive interpreter reads via PyOS_Readline, which may call whatever readline hook is installed.
I think the situation would be much more clear if something like my proposal was implemented (https://mail.python.org/pipermail/python-dev/2015-November/142246.html).
vadmium commentedon Jan 19, 2016
Adam: My experiments were assuming that PyOS_Readline() only ever uses the basic implementation or the Readline library, in order to see if there was any consistency with how Python worked in common situations.
There is actually a test that waits for the interpreter prompt on stderr; see test_cmd_line_script.CmdLineTest.interactive_python(). I realized that changing this would have to be considered carefully, because it could easily break other code as well. It certainly should not be done in a bug fix release.
Anyway I am proposing a patch in bpo-1927 to fix PyOS_StdioReadline(), so closing this as a duplicate.