python / python/cpython

Print from background thread has broken line endings

未關閉
#129,385 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-repl type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先,在 Linux 上使用 Python 3.13 以互動模式執行提供的指令碼,然後將其輸出與 Python 3.12 和非互動模式下的輸出進行比較。調查互動式提示字元和背景執行緒輸出的處理方式;完成標準是背景執行緒的行將游標返回到每行開頭,同時不干擾提示字元。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cli
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
冷清
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。