annoying CL echo in interactive python / ipython

K

kj

Under some parent shells, both my interactive python as well as
ipython, produce an unwanted echoing of the input line. E.g.
1 + 1
2
What's worse, upon exiting the interactive python/ipython session,
the terminal is left in echo mode:
% date
date
Tue Oct 19 13:27:47 EDT 2010
% stty -echo
% date
Tue Oct 19 13:27:50 EDT 2010

It's basically the same story for ipython.

(If I run stty -echo before running either python or ipython, I
still get the echo when I'm in them. So the problem is not a
pre-existing terminal setting.)

(As I said, this happens only under some shells (e.g. emacs shell),
so YMMV.)

Does anyone know how can I suppress this annoying feature?

TIA!

~kj
 
J

Jed Smith

Gee, thanks.  That really helped.  I'll go talk to my guru now,
and meditate over this.

You're right, I could have been more clear. I was nudging you to go
read the man page of stty(1), but since you won't and want to get
snarky instead, I will for you:
echo (-echo)
Echo back (do not echo back) every character typed.

I'm going to guess that the percent sign in your prompt indicates that
you're using zsh(1). With my minimally-customized zsh, the echo
option is reset every time the prompt is displayed. That means you can
type "stty -echo", push CR, the echo option is cleared, then zsh
immediately sets it before you get to type again. Therefore, you
cannot observe its *actual* behavior, and you assumed it had something
to do with what you're after. Am I on the right track?

Start bash, run stty -echo, then type. That is the ACTUAL behavior of
that option.

As to your original issue, your readline configuration is most likely
the problem. I consider it very unlikely that Python has anything to
do with it. I have no idea why fiddling with your terminal affects
readline, but there is a lot that I do not understand about readline.
 
H

Hrvoje Niksic

Jed Smith said:
That doesn't do what you think it does.

Really? Turning off tty echo sounds exactly like what he wants.

Emacs shell echoes characters for you, just like interactive shells do.
When you press enter, the characters are sent to a pseudo-terminal, and
if the pty echoes them, the input string will be printed twice, as the
OP observes. It is hard to tell what is going wrong in his setup and
whether it has anything to do with tty echoing, but it's a valid guess.
 
H

Hrvoje Niksic

Jed Smith said:
I'm going to guess that the percent sign in your prompt indicates that
you're using zsh(1). With my minimally-customized zsh, the echo
option is reset every time the prompt is displayed. That means you can
type "stty -echo", push CR, the echo option is cleared, then zsh
immediately sets it before you get to type again.

But are you running zsh in an emacs shell window? Emacs shell is not a
terminal emulator, it lets emacs do the editing, and only sends it to
the shell when enter is pressed. To avoid clashing with readline and
equivalent (ZLE in case of zsh), emacs presents itself as a dumb
terminal, which should make zsh turn ZLE off.
 
J

Jed Smith

But are you running zsh in an emacs shell window?  Emacs shell is not a
terminal emulator, it lets emacs do the editing, and only sends it to
the shell when enter is pressed.  To avoid clashing with readline and
equivalent (ZLE in case of zsh), emacs presents itself as a dumb
terminal, which should make zsh turn ZLE off.

I'll take your word for it, as I don't use emacs. That makes sense,
though, as while researching this question I did find documentation
that suggests zsh disables ZLE under emacs.

OP, it sounds like in this circumstance, then, that you want
interactive Python without readline (which means a recompile, and from
a quick Google it sounds like it might not work). I'd leave readline
in the system Python and just tell emacs to use my custom one without
it, if I were you.

(Or save the trouble and just run ipy in a separate xterm :>)
 
K

kj

You're right, I could have been more clear. I was nudging you to go
read the man page of stty(1), but since you won't and want to get
snarky instead, I will for you:

I read that, and it did not add anything new to what I already knew
about stty -echo.
I'm going to guess that the percent sign in your prompt indicates that
you're using zsh(1). With my minimally-customized zsh, the echo
option is reset every time the prompt is displayed. That means you can
type "stty -echo", push CR, the echo option is cleared, then zsh
immediately sets it before you get to type again.

Wrong guess. After I run "stty -echo", the echoing stays disabled:

% stty -echo
% date
Wed Oct 20 10:01:46 EDT 2010
% date
Wed Oct 20 10:01:47 EDT 2010
% date
Wed Oct 20 10:01:48 EDT 2010
% date
Wed Oct 20 10:01:49 EDT 2010

As to the guess about readline, I only observe this problem with
python (interactive) and ipython, but not with, say, the Perl
debugger, which uses readline as well. FWIW.

~kj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top