Skip to content

Multi-line input only processes the first line #9948

Open

Description

@languitar

With ipython 5.0 and 5.1 (from anaconda) I have the issue that multiple lines of input in one batch via the tty are not processed correctly. Only the first line is evaluated. This can be verified via tmux and the send-keys feature:

Start ipython in a tmux session:

tmux new -s test ipython

And send two lines of code in one batch from another terminal:

tmux send-keys -t 'test' 'print 42' Enter 'print 44' Enter

Only the first line is evaluated.

Activity

  1. Carreau commented on Sep 17, 2016

    @Carreau
    Member

    Hum, that's probably because the event arrive to fast for processing.
    You are basically typing print 44 while IPython in in between two prompt, as "enter" is both new line and execute (depending if the input is "complete" or not).

    if you try tmux send-keys -t 'test' 'for i in range(10):' Enter 'print 44' Enter if should work.

    We need to bind a shortcut that adds a new line without executing, if you are scripting you can use C-o Down to force a newline and Escape Enter to force execution.

  2. languitar commented on Sep 17, 2016

    @languitar
    Author

    My expectation would be that the unprocessed characters after the first enter are just queued up and processed once the first execution returns. This is the behavior that existed in previous versions and which I am used to from basically any other command-line based tool. Simply swallowing key presses doesn't sound nice to me.

  3. Carreau commented on Sep 17, 2016

    @Carreau
    Member

    I agree, I was just offering a work around. Though because of IPython
    architecture it might not be that easy to fix.

    The --simple-prompt option might fix that as well, but then you will lose
    most of the bells and whistles, syntactic coloration and multiline edit.

    Unfortunately there is a trade-off

    On Sep 17, 2016 05:05, "Johannes Wienke" [email protected] wrote:

    My expectation would be that the unprocessed characters after the first
    enter are just queued up and processed once the first execution returns.
    This is the behavior that existed in previous versions and which I am used
    to from basically any other command-line based tool. Simply swallowing key
    presses doesn't sound nice to me.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #9948 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAUezzQEQC_zTJvWjD7Gy1EOukxLFPiGks5qq9eegaJpZM4J8jia
    .

  4. ivanov commented on Mar 2, 2017

    @ivanov
    Member

    This issue may be the same as the one described in #9948. I want to address this by tackling #10364.

  5. jonathanslenders commented on Mar 4, 2017

    @jonathanslenders
    Contributor

    I guess the problem here is the send-keys command of tmux doesn't send keystrokes using bracketed paste. If you wrap everything in bracketed paste characters, then I think it should work.

    See: https://cirw.in/blog/bracketed-paste

  6. groner commented on Feb 20, 2018

    @groner

    I think paste is just one way of demonstrating the problem.

    Using ipython -im MODULE (or ipython -i SCRIPT) the repl can be delayed while the module or script is loaded, making it easy to type in multiple lines without using paste at all.

  7. marksteward commented on Sep 9, 2018

    @marksteward

    I hit this all the time just because of ipython's slow startup. I often find myself writing a couple of lines of code in the time it takes to load, and only the first of them is executed. --simple-prompt and rlwrap makes it usable again, but disables all the useful tab completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions