Issue1723

classification
Title: stdout not working; print redirected to stderr?
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.5
Milestone:
process
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: amak, fwierzbicki, jasonsmith, pjenvey, zyasoft
Priority: low Keywords: console

Created on 2011-03-23.20:33:59 by jasonsmith, last changed 2015-04-19.22:44:30 by zyasoft.

Messages
msg6451 (view) Author: Jason Smith (jasonsmith) Date: 2011-03-23.20:33:59
From interactive mode:
>>> import sys
>>> sys.stdout.write("Hello.")
>>> sys.stderr.write("Hello.")
Hello.>>>

The first write should print 'Hello.' to console, but prints nothing.

I also noticed it looks like the print command is printing to stderr, not to stdout (at least it looks like this from another program I have with colored output).
msg6452 (view) Author: Jason Smith (jasonsmith) Date: 2011-03-23.20:36:15
This bug should be against 2.5.2 final.  I don't see it in the list.  On Ubuntu 10.10.
msg6453 (view) Author: Jason Smith (jasonsmith) Date: 2011-03-23.20:58:06
The behavior is as expected when using the -u flag.
msg6454 (view) Author: Jason Smith (jasonsmith) Date: 2011-03-23.22:16:52
It works if you follow the command by sys.stdout.flush().  The difference between Python and Jython behavior appears to be autoflush.
msg6456 (view) Author: Philip Jenvey (pjenvey) Date: 2011-03-24.20:51:44
IIRC our problem is our JLine console reader doesn't actually output everything (like the >>> prompt) via sys.stdout. If you disable it and use the bare minimum console I believe we'd match CPython's behavior

So on CPython you're seeing autoflush like behavior because the prompt is immediately printed afterwards and a flush is done to ensure the prompt shows up

Otherwise you'd see similar behavior in cpython if you did:

>>> sys.stdout.write('hello'); time.sleep(2)

Anyway I see this as a very minor implementation detail, but it would be nice to fix this at some point. Though it may be problematic to fix (see #695383 for a somewhat related problem)
msg9900 (view) Author: Jim Baker (zyasoft) Date: 2015-04-19.22:44:30
So we are writing this output out immediately, per msg6451, however, it does interact poorly with the console prompt being redisplayed by JLine2:

>>> sys.stdout.write("Hello.")
Hello.>>> sys.stderr.write("Hello.")
>>> o.>>>

where as CPython 2.7 does the following:

>>> import sys
>>> sys.stdout.write("Hello.")
Hello.>>> sys.stderr.write("Hello.")
Hello.>>>
History
Date User Action Args
2015-04-19 22:44:30zyasoftsetnosy: + zyasoft
messages: + msg9900
2013-02-25 22:03:01amaksetkeywords: + console
nosy: + amak
2013-02-20 00:08:55fwierzbickisetnosy: + fwierzbicki
resolution: remind
versions: + Jython 2.5, - 2.5.2rc
2011-03-24 20:51:45pjenveysetpriority: low
nosy: + pjenvey
messages: + msg6456
components: + Core, - Any
2011-03-23 22:16:52jasonsmithsetmessages: + msg6454
2011-03-23 20:58:06jasonsmithsetmessages: + msg6453
2011-03-23 20:36:15jasonsmithsetmessages: + msg6452
2011-03-23 20:33:59jasonsmithcreate