python / python/cpython

Print from background thread has broken line endings

Đang mở
#129,385 7 bình luận 0 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:

I noticed that in python 3.13 (in linux), messages that were previously logged nicely to the console are now behaving as if the lines end like a windows line feed character without carriage return -- the cursor moves down a row, but not back to the beginning of the line. The example I chose below looks tame, but it makes most real logging output very difficult to read.

This only seems to happen for lines printed from background threads:

import threading, time

def msg():
    print('this is line 1')
    print('this is line 2')
    time.sleep(0.1)  # first few lines work as expected, but after a brief time, the problem begins
    print('this is line 3')
    print('this is line 4')

thread = threading.Thread(target=msg)
thread.start()

Running this code in python 3.13.1, interactive mode looks like:

$ python -i print_test.py 
this is line 1
this is line 2
>>> this is line 3
                  this is line 4
                            >>>

Non-interactive looks fine:

$ python print_test.py 
this is line 1
this is line 2
this is line 3
this is line 4

And interactive in 3.12.8 looks fine:

$ python -i print_test.py 
this is line 1
this is line 2
>>> this is line 3
this is line 4
CPython versions tested on:

3.13

Operating systems tested on:

Linux

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 bằng cách chạy script được cung cấp ở chế độ tương tác trên Linux với Python 3.13, sau đó so sánh đầu ra của nó với Python 3.12 và chế độ không tương tác. Điều tra việc xử lý dấu nhắc tương tác và đầu ra của thread nền; công việc được xem là hoàn tất khi các dòng từ thread nền đưa con trỏ về đầu mỗi dòng mà không làm gián đoạn dấu nhắc.

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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/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.