Skip to content

Print from background thread has broken line endings #129385

@campagnola

Description

@campagnola

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions