Skip to content

Jupyter shebang cells won't show partially written lines #14648

@divyansshhh

Description

@divyansshhh

When a shebang cell (i.e., %%sh, %%bash, etc.) in a Jupyter notebook writes/flushes output, the output doesn't show up until the script ends or a newline is written. This hurts the usability of programs that indicate progress by writing periodically on the same line.

Changing this ipython logic to read whatever text is available (rather than waiting for a newline) would fix the issue: https://github.com/ipython/ipython/blob/18e45295c06eb9/IPython/core/magics/script.py#L215. (I'm not familiar with asyncio's streams, so it might also be necessary to ensure the fd is in non-blocking mode.)

Below is a GIF demonstrating the issue. Observe that:

  1. The output regular Python cell updates in realtime, even if it doesn't include a newline.
  2. The output an equivalent shebang cell does not update in realtime.
  3. The output of a shebang cell that includes newlines updates in realtime.

Image

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