Skip to content

The new REPL floods the output when stdout is a broken pipe #142948

@johnslavik

Description

@johnslavik

Bug report

Bug description:

The new REPL assumes that writing to stdout would never raise BrokenPipeError, so it doesn't guard against it.

In some rare scenarios this can cause spurious output flood.

I’m attaching a short video demonstrating the issue. An example case of broken pipe is when the stdout is piped to xargs, and xargs receives SIGINT, breaking pipe. There might exist some more realistic scenarios though, perhaps.

Note: the video contains rapidly changing on‑screen text, which may be uncomfortable for some viewers (e.g. those with photosensitivity).

Screencast.From.2025-12-18.18-07-37.mp4

(This would loop forever -- I've pressed Ctrl+C and then Ctrl+C again)

A way to workaround the problem is to disable the new REPL entirely (i.e., fall back to basic REPL) if the stdout is non-interactive -- this is what I'm proposing in the PR. The new REPL's functions emulating curses are complex and I didn't want to further complicate them just to cover extremely rare edge cases.

If that's too aggressive, we could just guard against the broken pipe error when writing to stdout.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions