Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print from background thread has broken line endings #129385

Open
campagnola opened this issue Jan 28, 2025 · 1 comment
Open

Print from background thread has broken line endings #129385

campagnola opened this issue Jan 28, 2025 · 1 comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@campagnola
Copy link

campagnola commented Jan 28, 2025

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

@campagnola campagnola added the type-bug An unexpected behavior, bug, or error label Jan 28, 2025
@encukou encukou added the topic-repl Related to the interactive shell label Jan 28, 2025
@encukou
Copy link
Member

encukou commented Jan 28, 2025

This is most likely because the new REPL modifies the terminal settings, assuming it's the only thing printing there.
As a workaround you can run PYTHON_BASIC_REPL=1 python to use the old REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants