Issue2089

classification
Title: sys.stdout not flushed after sys.exit
Type: Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jeff.allen Nosy List: cdleonard, jeff.allen, zyasoft
Priority: Keywords: console

Created on 2013-09-20.14:01:41 by cdleonard, last changed 2014-03-27.18:25:19 by jeff.allen.

Files
File name Uploaded Description Edit Remove
unnamed zyasoft, 2014-03-04.16:36:53
unnamed zyasoft, 2014-03-17.01:34:59
Messages
msg8121 (view) Author: Leonard Crestez (cdleonard) Date: 2013-09-20.14:01:40
Same code is very simple:

import sys
sys.stdout.write('hello')
sys.exit(0)

This prints "hello" (without EOL) with cpython and nothing with jython. It behaves as expected if either the sys.exit statement is removed or an EOL is printed.

This should behave like python. Writing something to stdout without EOL is perfectly valid.
msg8122 (view) Author: Jim Baker (zyasoft) Date: 2013-09-20.15:23:43
Apparently the problem is that only files opened in Python code use the codepath in PyFile that registers a closer; PySystemState uses a different path that does not do this. Should be an easy fix.
msg8244 (view) Author: Jeff Allen (jeff.allen) Date: 2014-03-04.09:12:05
I confirm this behaviour. Choosing not to have the fancy console is the work-around:

>dist\bin\jython -Dpython.console= -c "import sys; sys.stdout.write('hello')"
hello
>

I'm pretty sure I broke this. The wrapper I made for the fancy console keeps each unterminated output line, defeating the upstream flush() until you start a read. This is the only way I found to get the line editing JLineConsole to know about the prompt.

As Jim comments, what's needed here is to give my clever wrapper a Closer that will flush the "prompt" you never used.
msg8245 (view) Author: Jim Baker (zyasoft) Date: 2014-03-04.16:36:54
sys is problematic in Python, or at least the Jython implementation, given
its unique role - we always seems to be special casing for it. This is just
one more example - we want better console support and we need specific
Closer support.

At least it should be an easy fix.

On Tue, Mar 4, 2014 at 2:12 AM, Jeff Allen <report@bugs.jython.org> wrote:

>
> Jeff Allen added the comment:
>
> I confirm this behaviour. Choosing not to have the fancy console is the
> work-around:
>
> >dist\bin\jython -Dpython.console= -c "import sys;
> sys.stdout.write('hello')"
> hello
> >
>
> I'm pretty sure I broke this. The wrapper I made for the fancy console
> keeps each unterminated output line, defeating the upstream flush() until
> you start a read. This is the only way I found to get the line editing
> JLineConsole to know about the prompt.
>
> As Jim comments, what's needed here is to give my clever wrapper a Closer
> that will flush the "prompt" you never used.
>
> ----------
> assignee:  -> jeff.allen
> keywords: +console
> nosy: +jeff.allen
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue2089>
> _______________________________________
>
>
msg8253 (view) Author: Jeff Allen (jeff.allen) Date: 2014-03-16.17:54:54
There are actually two problems here, I realise, and the sys.exit() call is critical:
>dist\bin\jython -c "import sys; sys.stdout.write('hello')"

>dist\bin\jython -Dpython.console= -c "import sys; sys.stdout.write('hello')"
hello
>dist\bin\jython -Dpython.console= -c "import sys; sys.stdout.write('hello'); sys.exit(0)"

>
I see that avoiding a fancy console only avoided one of these, where sys.exit is not called. That one is fixed (on my repo), although not in the way I proposed; now I need to find the other.
msg8254 (view) Author: Jeff Allen (jeff.allen) Date: 2014-03-16.23:27:06
Fixed, I claim, in http://hg.python.org/jython/rev/aa042b69bdda, although the change set before it is necessary when a fancy console is installed (as it is by default). I now get:

>dist\bin\jython -c "import sys; sys.stdout.write('hello'); sys.exit(0)"
hello
>dist\bin\jython -Dpython.console= -c "import sys; sys.stdout.write('hello');sys.exit(0)"
hello
>
msg8255 (view) Author: Jim Baker (zyasoft) Date: 2014-03-17.01:35:00
Great news! That's completely different than what I originally thought,
nice spotting that bug.

- Jim

On Sun, Mar 16, 2014 at 5:27 PM, Jeff Allen <report@bugs.jython.org> wrote:

>
> Jeff Allen added the comment:
>
> Fixed, I claim, in http://hg.python.org/jython/rev/aa042b69bdda, although
> the change set before it is necessary when a fancy console is installed (as
> it is by default). I now get:
>
> >dist\bin\jython -c "import sys; sys.stdout.write('hello'); sys.exit(0)"
> hello
> >dist\bin\jython -Dpython.console= -c "import sys;
> sys.stdout.write('hello');sys.exit(0)"
> hello
> >
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue2089>
> _______________________________________
>
>
History
Date User Action Args
2014-03-27 18:25:19jeff.allensetstatus: open -> closed
resolution: accepted -> fixed
2014-03-17 01:35:00zyasoftsetfiles: + unnamed
messages: + msg8255
2014-03-16 23:27:06jeff.allensetmessages: + msg8254
2014-03-16 17:54:55jeff.allensetmessages: + msg8253
2014-03-04 16:36:54zyasoftsetfiles: + unnamed
messages: + msg8245
2014-03-04 09:12:07jeff.allensetkeywords: + console
assignee: jeff.allen
messages: + msg8244
nosy: + jeff.allen
2013-09-20 15:23:43zyasoftsetresolution: accepted
messages: + msg8122
nosy: + zyasoft
2013-09-20 14:01:41cdleonardcreate