python / python/cpython

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

Đang mở
#157,581 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-repl type-bug
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với traceback của _pyrepl và entry point can_colorize trong _colorize.py, khoảng dòng 313, sau đó tái hiện trường hợp sys.stdout bị đóng trong REPL Python 3.14. Hoàn tất có nghĩa là stdout bị đóng không còn tạo ra một chuỗi traceback vô tận và REPL xử lý đúng prompt tiếp theo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
cli
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.