Title: PyOS_StdioReadline is printing the prompt on stderr
Type: behavior Stage:
Components: Extension Modules Versions: Python 3.6, Python 3.5, Python 3.4, Python 3.3, Python 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Albert.Zeyer, Drekin, martin.panter
Priority: normal Keywords:

Created on 2011-08-31 14:38 by Albert.Zeyer, last changed 2015-11-22 12:32 by Drekin.

Messages (5)
msg143256 - (view) Author: Albert Zeyer (Albert.Zeyer) Date: 2011-08-31 14:38
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.stderr` and not the system stderr.
msg196114 - (view) Author: Adam Bartoš (Drekin) * Date: 2013-08-25 08:40
Related stackoverflow question: .
msg247982 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-08-04 04:30
Results of experimenting on 3.6:

* 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 Issue 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 Issue 17620, about redirecting sys.stdin.
msg255077 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-22 00:14
Actually Issue 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.
msg255096 - (view) Author: Adam Bartoš (Drekin) * Date: 2015-11-22 12:32
> * 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.

I think the situation would be much more clear if something like my proposal was implemented (
Date User Action Args
2015-11-22 12:32:16Drekinsetmessages: + msg255096
2015-11-22 00:14:32martin.pantersetmessages: + msg255077
2015-08-04 04:30:06martin.pantersetnosy: + martin.panter

messages: + msg247982
versions: + Python 3.5, Python 3.6
2013-08-25 08:40:06Drekinsetnosy: + Drekin
messages: + msg196114
2013-02-19 20:10:23ezio.melottisettype: behavior
components: + Extension Modules
versions: + Python 3.3, Python 3.4
2011-08-31 14:38:37Albert.Zeyercreate