python / python/cpython

Print from background thread has broken line endings

Open
#129,385 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-repl type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied script with interactive mode on Linux under Python 3.13, then compare its output with Python 3.12 and non-interactive mode. Investigate the interactive prompt and background-thread output handling; done means background-thread lines return the cursor to the start of each line without disrupting the prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.