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

[BUG] Double rendering of notebook output with rich>=12.6.0 #2740

Closed
2 tasks done
alecgunny opened this issue Jan 9, 2023 · 7 comments · Fixed by #2804
Closed
2 tasks done

[BUG] Double rendering of notebook output with rich>=12.6.0 #2740

alecgunny opened this issue Jan 9, 2023 · 7 comments · Fixed by #2804

Comments

@alecgunny
Copy link

Describe the bug
It appears the double rendering issue referenced in #1737 has returned starting in version 12.6.0.

With a poetry environment given by:

[tool.poetry]
name = "rich-bug-repro"
version = "0.0.1"
description = "..."
authors = ["John Doe"]

[tool.poetry.dependencies]
python = "^3.9"
jupyter = "^1.0.0"
rich = {version = "x.x.x", extras=["jupyter"]}  # fill out with desired version

a simple reproducing example is (from a jupyter notebook)

from rich.progress import track
import time

for i in track(range(100)):
    time.sleep(0.01)

when version is set to any of 12.6.0,13.0.0,13.0.1 in the pyproject.toml above, the output of this example looks like

image

When using <12.6.0, you get the expected
image

Note that this is strictly a jupyter problem: for any of these versions, running e.g.

python -c 'from rich.progress import track;import time;[time.sleep(0.01) for _ in track(range(100))]'

results in just a single progress bar being printed, as expected.

Platform

Click to expand

What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Linux, both natively and in WSL2 on Windows.

I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.

If you're using Rich in a terminal:

python -m rich.diagnose
pip freeze | grep rich

If you're using Rich in a Jupyter Notebook, run the following snippet in a cell
and paste the output in your bug report.

from rich.diagnose import report
report()
╭────────────────────── <class 'rich.console.Console'> ──────────────────────╮
│ A high level console interface.                                            │
│                                                                            │
│ ╭────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=115 ColorSystem.TRUECOLOR>                              │ │
│ ╰────────────────────────────────────────────────────────────────────────╯ │
│                                                                            │
│     color_system = 'truecolor'                                             │
│         encoding = 'utf-8'                                                 │
│             file = <ipykernel.iostream.OutStream object at 0x7f3f783203d0> │
│           height = 100                                                     │
│    is_alt_screen = False                                                   │
│ is_dumb_terminal = False                                                   │
│   is_interactive = True                                                    │
│       is_jupyter = True                                                    │
│      is_terminal = True                                                    │
│   legacy_windows = False                                                   │
│         no_color = False                                                   │
│          options = ConsoleOptions(                                         │
│                        size=ConsoleDimensions(width=115, height=100),      │
│                        legacy_windows=False,                               │
│                        min_width=1,                                        │
│                        max_width=115,                                      │
│                        is_terminal=True,                                   │
│                        encoding='utf-8',                                   │
│                        max_height=100,                                     │
│                        justify=None,                                       │
│                        overflow=None,                                      │
│                        no_wrap=False,                                      │
│                        highlight=None,                                     │
│                        markup=None,                                        │
│                        height=None                                         │
│                    )                                                       │
│            quiet = False                                                   │
│           record = False                                                   │
│         safe_box = True                                                    │
│             size = ConsoleDimensions(width=115, height=100)                │
│        soft_wrap = False                                                   │
│           stderr = False                                                   │
│            style = None                                                    │
│         tab_size = 8                                                       │
│            width = 115                                                     │
╰────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available.                           │
│                                                       │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│                                                       │
│ truecolor = False                                     │
│        vt = False                                     │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ {                                  │
│     'TERM': 'xterm-color',         │
│     'COLORTERM': None,             │
│     'CLICOLOR': '1',               │
│     'NO_COLOR': None,              │
│     'TERM_PROGRAM': None,          │
│     'COLUMNS': None,               │
│     'LINES': None,                 │
│     'JUPYTER_COLUMNS': None,       │
│     'JUPYTER_LINES': None,         │
│     'JPY_PARENT_PID': '2054',      │
│     'VSCODE_VERBOSE_LOGGING': None │
│ }                                  │
╰────────────────────────────────────╯
platform="Linux"
@Textualize Textualize deleted a comment from github-actions bot Feb 12, 2023
@willmcgugan
Copy link
Collaborator

What software are you using to run the Notebook? Jupyter notebook, Jupyter lab, VSCode ?

@makkus
Copy link

makkus commented Feb 12, 2023

I had the same problem, was using Jupyter lab.

@makkus
Copy link

makkus commented Feb 12, 2023

Ok, just checked again, and the problem exists with both jupyter-lab and notebook. Don't use VSCode, so don't know about that. In my case, both running on Linux, in a (newly created) conda-environment, if that makes any difference.

@minrk
Copy link
Contributor

minrk commented Feb 12, 2023

FWIW, I tracked this down to #2449 setting _force_terminal=True because FORCE_COLOR=1 tends to be set in Jupyter. If you launch with a Console(force_terminal=False), the problem goes away.

I don't know enough about rich to identify exactly which output produced when Console.is_terminal = True causes the duplicate lines, but you can see the difference:

Screenshot 2023-02-13 at 00 00 52

copyable code
import time

import rich
from rich.console import Console
from rich.progress import Progress

with Progress() as p:
    for i in p.track(range(10), description="duplicate"):
        time.sleep(0.1)

with Progress(console=Console(force_terminal=False)) as p:
    for i in p.track(range(10), description="fixed"):
        time.sleep(0.1)

@github-actions
Copy link

github-actions bot commented Mar 4, 2023

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

@basnijholt
Copy link
Contributor

This still happens for me in VS Code:
image

@pejmanS21
Copy link

pejmanS21 commented Feb 28, 2024

This still happens for me in VS Code: image

We still have this issue, any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants