Issue1823

classification
Title: jython launcher bash script induces terminal malfunction
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.5
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amak, fwierzbicki, otmarhumbel, slestak, zyasoft
Priority: normal Keywords: console

Created on 2011-11-23.21:16:15 by slestak, last changed 2015-04-19.22:21:58 by zyasoft.

Messages
msg6731 (view) Author: Steve Romanow (slestak) Date: 2011-11-23.21:16:15
when I execute an interactive session or run a script with output, my terminals stty is left in a bad state.  I have to run stty sane afterwards to get it back.  I tested ksh, bash, bash + tmux and all the same behavior.

This is AIX 5.3.

A workaround I have is to add "stty sane" to the 2nd to last line in bin/jython.
msg6827 (view) Author: Alan Kennedy (amak) Date: 2012-03-19.18:06:20
Please define "bad state": some details are necessary to know what the issues are.

Also, what is your setting for the following options in the registry file?

python.console = ????
python.console.readlinelib = ????
msg6898 (view) Author: Steve Romanow (slestak) Date: 2012-03-19.22:44:09
It is set to the default.  I bet it will work well if I try some of these.

What would happen is any time I printed to stdout (and possibly
stderr) the console would be corrupted.  When I press return, the
prompt woould print to the right, instead of down to a newline.

Putting stty sane in my launcher script got it working as a workaround.

On Mon, Mar 19, 2012 at 2:06 PM, Alan Kennedy <report@bugs.jython.org> wrote:
>
> Alan Kennedy <jython-dev@xhaus.com> added the comment:
>
> Please define "bad state": some details are necessary to know what the issues are.
>
> Also, what is your setting for the following options in the registry file?
>
> python.console = ????
> python.console.readlinelib = ????
>
> ----------
> nosy: +amak
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue1823>
> _______________________________________
msg6901 (view) Author: Alan Kennedy (amak) Date: 2012-03-19.22:58:20
Please can you paste the output of this code?

>>> import sys
>>> sys.registry['python.console']
>>> sys.registry['python.console.readlinelib']

Also, have you tried any other options for these settings in the registry file? Are there any settings that do not cause the problem?
msg6909 (view) Author: Steve Romanow (slestak) Date: 2012-03-20.02:39:18
I will have to look tomorrow.  The machine is at work.

On Mon, Mar 19, 2012 at 6:58 PM, Alan Kennedy <report@bugs.jython.org> wrote:
>
> Alan Kennedy <jython-dev@xhaus.com> added the comment:
>
> Please can you paste the output of this code?
>
>>>> import sys
>>>> sys.registry['python.console']
>>>> sys.registry['python.console.readlinelib']
>
> Also, have you tried any other options for these settings in the registry file? Are there any settings that do not cause the problem?
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue1823>
> _______________________________________
msg6921 (view) Author: Steve Romanow (slestak) Date: 2012-03-20.13:32:14
For these tests, I commented out my "stty sane" that is my next to
last executable line in /usr/local/bin/jython.

Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[IBM J9 VM (IBM Corporation)] on java1.5.0
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.registry['python.console']
>>> sys.registry['python.console.readlinelib']
>>>
bash-4.2$ bash-4.2$ bash-4.2$ bash-4.2$ bash-4.2$ bash-4.2$

Note how when I left the jython interpreter, my bash prompts started
going horizontally when I press carriage return.

I see that the default charset appears to be cp850.  I know out box
will prob react better to iso-8859-1 (aka latin1).  I will try that
and see if it helps.

Ok, changing the charset only did not help the problem.  Changing it
back to default.

Alright, using the last option in the list does not have the problem.

python.console=org.python.util.InteractiveConsole

The question now is if we want to continue trying to make jline work
with my setup?  I have to believe jython on aix is a corner case, but
if its a trivial fix why not?
msg6936 (view) Author: Alan Kennedy (amak) Date: 2012-03-20.21:31:07
So a bit of googling reveals that jline can change your terminal settings, particularly the echo setting, which explains the behaviour you're seeing.

This jline message seems relevant

Why doesn't jline enable the echo after exit?
https://groups.google.com/forum/#!topic/jline-users/I8r3-UYnbQM

Particluarly, it looks like calling

jline.TerminalSupport.restore()

Might restore your terminal.

http://www.jarvana.com/jarvana/view/org/sonatype/jline/jline/2.3/jline-2.3-javadoc.jar!/jline/TerminalSupport.html

Can you give that a try? If it works, perhaps we'll have to add such a call to jython exit hooks, when jline is in use.
msg6938 (view) Author: Steve Romanow (slestak) Date: 2012-03-20.21:51:54
I'm sorry.  I do not know how to use the jline method.  import it and
call it in the jython interpreter?

I also noticed the problem does not occur when you type exit().  Only
when you exit the interpreter with a Ctl-D it seems.

I see jline has an IsEchoEnabled() method.  Maybe it needs to check
before instantiating jline and just put it back to what it was, all
the time.

On Tue, Mar 20, 2012 at 5:31 PM, Alan Kennedy <report@bugs.jython.org> wrote:
>
> Alan Kennedy <jython-dev@xhaus.com> added the comment:
>
> So a bit of googling reveals that jline can change your terminal settings, particularly the echo setting, which explains the behaviour you're seeing.
>
> This jline message seems relevant
>
> Why doesn't jline enable the echo after exit?
> https://groups.google.com/forum/#!topic/jline-users/I8r3-UYnbQM
>
> Particluarly, it looks like calling
>
> jline.TerminalSupport.restore()
>
> Might restore your terminal.
>
> http://www.jarvana.com/jarvana/view/org/sonatype/jline/jline/2.3/jline-2.3-javadoc.jar!/jline/TerminalSupport.html
>
> Can you give that a try? If it works, perhaps we'll have to add such a call to jython exit hooks, when jline is in use.
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue1823>
> _______________________________________
msg6939 (view) Author: Alan Kennedy (amak) Date: 2012-03-20.22:19:04
> I also noticed the problem does not occur when you type exit().  Only
> when you exit the interpreter with a Ctl-D it seems.

That's interesting.

I found this issue, which seems to be related.

JLine is not restoring terminal settings appropriately on some linux environments
http://code.google.com/p/jaql/issues/detail?id=81

Key quote: "Problem turns out to be related to using the IBM jdk.  Jline restores the console correctly with the Sun jdk."

They also have a fix: looks like we might need to include something similar in our invocation script.

http://code.google.com/p/jaql/source/diff?spec=svn551&r=551&format=side&path=/trunk/bin/jaqlshell

So it appears that your addition of "stty sane" to the end of the jython invocation script was the right way to go.
msg6973 (view) Author: Alan Kennedy (amak) Date: 2012-03-28.20:01:35
Adding Oti.

Oti, do you think it worthwhile to add "stty sane" to the jython bash script?

If you read through the messages of this bug, it appears to be a good solution to a problem that appears on AIX.
msg6974 (view) Author: Steve Romanow (slestak) Date: 2012-03-29.03:11:36
Maybe at least a comment mentioning it in the config, since there are
configurable terminal libraries.

On Wed, Mar 28, 2012 at 4:01 PM, Alan Kennedy <report@bugs.jython.org> wrote:
>
> Alan Kennedy <jython-dev@xhaus.com> added the comment:
>
> Adding Oti.
>
> Oti, do you think it worthwhile to add "stty sane" to the jython bash script?
>
> If you read through the messages of this bug, it appears to be a good solution to a problem that appears on AIX.
>
> ----------
> nosy: +otmarhumbel
>
> _______________________________________
> Jython tracker <report@bugs.jython.org>
> <http://bugs.jython.org/issue1823>
> _______________________________________
msg6975 (view) Author: Oti Humbel (otmarhumbel) Date: 2012-03-29.08:13:26
"stty sane" sounds reasonable to me.

I am in the process of migrating the installer project from svn to hg and therefore defer any changes to the installer until then.
msg7755 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-25.20:51:33
So the installer is now migrated if you want to look at this Oti :) -- if not maybe an AIX user can provide a patch?
msg9895 (view) Author: Jim Baker (zyasoft) Date: 2015-04-19.22:21:58
Is this still an issue on AIX, now that we have moved to JLine2?

We could readily do this in the new launcher itself (jython.py) if necessary. To totally remove the need for the bash version, we may also relax jython.py's dependency on running on CPython 2.7 (because of argparse), and allow it on any recent CPython version.
History
Date User Action Args
2015-04-19 22:21:58zyasoftsetassignee: otmarhumbel ->
messages: + msg9895
nosy: + zyasoft
2013-02-25 21:54:10amaksetkeywords: + console
2013-02-25 20:51:34fwierzbickisetpriority: normal
messages: + msg7755
versions: + Jython 2.5, - 2.5.2
2012-03-29 08:13:27otmarhumbelsetassignee: otmarhumbel
messages: + msg6975
2012-03-29 03:11:36slestaksetmessages: + msg6974
2012-03-28 20:01:35amaksetnosy: + otmarhumbel
messages: + msg6973
2012-03-20 22:19:04amaksetmessages: + msg6939
2012-03-20 21:51:55slestaksetmessages: + msg6938
2012-03-20 21:31:07amaksetmessages: + msg6936
2012-03-20 17:45:45fwierzbickisetnosy: + fwierzbicki
2012-03-20 13:32:14slestaksetmessages: + msg6921
2012-03-20 02:39:18slestaksetmessages: + msg6909
2012-03-19 22:58:20amaksetmessages: + msg6901
2012-03-19 22:44:09slestaksetmessages: + msg6898
2012-03-19 18:06:21amaksetnosy: + amak
messages: + msg6827
2011-11-23 21:16:15slestakcreate