python / python/cpython

Closed `sys.stdout` causes an endless stream of tracebacks in the repl

Offen
#157,581 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib topic-repl type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug report

Bug description:
Steps to reproduce:

Run Python 3.14.7 and enter the following:

import sys
f = open("file.txt", "w")
sys.stdout = f
f.close()

After the file is closed, the REPL attempts to display the next prompt.

Actual behavior:

The REPL repeatedly raises:

ValueError: I/O operation on closed file

This results in a very large stream of repeated tracebacks instead of returning to a usable prompt.
The traceback points to _pyrepl and eventually to:

_colorize.py", line 313, in can_colorize
    return os.isatty(file.fileno())
ValueError: I/O operation on closed file
Expected behavior:

The REPL should handle a closed sys.stdout gracefully instead of repeatedly emitting tracebacks.

Environment:

Python: 3.14.7
OS: Fedora Linux 44 (Workstation Edition) x86_64

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-157590

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem _pyrepl-Traceback und dem can_colorize-Einstiegspunkt in _colorize.py ungefähr bei Zeile 313, und reproduziere dann den Fall mit geschlossenem sys.stdout in der Python 3.14 REPL. Erledigt ist die Aufgabe, wenn ein geschlossenes stdout keinen endlosen Strom von Tracebacks mehr erzeugt und die REPL den nächsten Prompt ordnungsgemäß verarbeitet.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.