annoying CL echo in interactive python / ipython

Discussion in 'Python' started by kj, Oct 19, 2010.

  1. kj

    kj Guest

    Under some parent shells, both my interactive python as well as
    ipython, produce an unwanted echoing of the input line. E.g.

    >>> 1 + 1

    1 + 1
    2
    >>>


    What's worse, upon exiting the interactive python/ipython session,
    the terminal is left in echo mode:

    >>> <EOF>

    % 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
    kj, Oct 19, 2010
    #1
    1. Advertising

  2. kj

    Jed Smith Guest

    On Tue, Oct 19, 2010 at 1:37 PM, kj <> wrote:

    > % stty -echo


    That doesn't do what you think it does.

    --
    Jed Smith
    Jed Smith, Oct 19, 2010
    #2
    1. Advertising

  3. kj

    kj Guest

    In <> Jed Smith <> writes:

    >On Tue, Oct 19, 2010 at 1:37 PM, kj <> wrote:


    >> % stty -echo


    >That doesn't do what you think it does.


    Gee, thanks. That really helped. I'll go talk to my guru now,
    and meditate over this.
    kj, Oct 19, 2010
    #3
  4. kj

    Jed Smith Guest

    On Tue, Oct 19, 2010 at 2:35 PM, kj <> wrote:
    > In <> Jed Smith <> writes:
    >
    >>On Tue, Oct 19, 2010 at 1:37 PM, kj <> wrote:

    >
    >>> % stty -echo

    >
    >>That doesn't do what you think it does.

    >
    > 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.

    --
    Jed Smith
    Jed Smith, Oct 19, 2010
    #4
  5. Jed Smith <> writes:

    > On Tue, Oct 19, 2010 at 1:37 PM, kj <> wrote:
    >
    >> % stty -echo

    >
    > 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.
    Hrvoje Niksic, Oct 19, 2010
    #5
  6. Jed Smith <> writes:

    >> 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.


    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.
    Hrvoje Niksic, Oct 19, 2010
    #6
  7. kj

    Jed Smith Guest

    On Tue, Oct 19, 2010 at 3:33 PM, Hrvoje Niksic <> wrote:
    > Jed Smith <> writes:
    >
    >>>     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.

    >
    > 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 :>)

    --
    Jed Smith
    Jed Smith, Oct 19, 2010
    #7
  8. kj

    kj Guest

    In <> Jed Smith <> writes:

    >On Tue, Oct 19, 2010 at 2:35 PM, kj <> wrote:
    >> In <> Jed Smith <jed@jed=

    >smith.org> writes:
    >>
    >>>On Tue, Oct 19, 2010 at 1:37 PM, kj <> wrote:

    >>
    >>>> % stty -echo

    >>
    >>>That doesn't do what you think it does.

    >>
    >> Gee, thanks. =A0That really helped. =A0I'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 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
    kj, Oct 20, 2010
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WJ
    Replies:
    2
    Views:
    484
  2. bdb112
    Replies:
    2
    Views:
    1,168
    Jason Scheirer
    Mar 12, 2009
  3. hong zhang

    python with echo

    hong zhang, Nov 12, 2009, in forum: Python
    Replies:
    6
    Views:
    2,139
  4. Wolfram Brenig

    ipython -wthread vs. ipython -pylab

    Wolfram Brenig, Sep 12, 2011, in forum: Python
    Replies:
    0
    Views:
    338
    Wolfram Brenig
    Sep 12, 2011
  5. Anoop Thomas Mathew
    Replies:
    0
    Views:
    112
    Anoop Thomas Mathew
    Nov 9, 2013
Loading...

Share This Page