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] Live Progress Bars Double-Render in Jupyter Notebooks #1737

Closed
nicholaswold opened this issue Dec 3, 2021 · 8 comments
Closed

[BUG] Live Progress Bars Double-Render in Jupyter Notebooks #1737

nicholaswold opened this issue Dec 3, 2021 · 8 comments

Comments

@nicholaswold
Copy link

Describe the bug

Upgrading to 10.15.1 from 10.13.0 causes a double-render when using a live progress bar in a Jupyter Notebook. You can see this easily using the following example code:

from rich.progress import Progress

with Progress() as progress:
    task1 = progress.add_task("[red]Downloading...", total=2)
    while not progress.finished:
        progress.update(task1, advance=1)
        progress.refresh()

image

If it matters, we were using ipywidgets==7.6.5 for this example above. Rolling back to rich==10.13.0 fixed the issue.

You can see the section below for a description of what's happening in the Jupyter messaging protocol, but my best guess is that the ipywidgets usage is slightly off and causing this bug.

ipywidgets specifics

Normally when you update an output widget it fires the following messages:

  1. A comm_msg that specifies that all future messages apply to a specific output model
  2. A clear_output message with wait=True
  3. A display_data message including the new content
  4. A comm_msg that specifies that future messages no longer apply to a specific output model

We were noticing that this is still the case except for the final update message, in which it does the following:

  1. A comm_msg that specifies that all future messages apply to a specific output model
  2. A clear_output message with wait=True
  3. A comm_msg that specifies that future messages no longer apply to a specific output model
  4. A display_data message including the new content

The swap of those two messages caused the double-render, because the old render is never cleared by an output to that widget model, and the display_data is tracked as a new output for the cell.

Platform

Underlying platform is linux, using the classic Jupyter interface. This also happened using Noteable's interface.

╭─────────────────────── <class 'rich.console.Console'> ───────────────────────╮
│ A high level console interface.                                              │
│                                                                              │
│ ╭──────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=80 None>                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
│                                                                              │
│     color_system = None                                                      │
│         encoding = 'utf-8'                                                   │
│             file = <_io.TextIOWrapper name='<stdout>' mode='w'               │
│                    encoding='utf-8'>                                         │
│           height = 25                                                        │
│    is_alt_screen = False                                                     │
│ is_dumb_terminal = False                                                     │
│   is_interactive = False                                                     │
│       is_jupyter = False                                                     │
│      is_terminal = False                                                     │
│   legacy_windows = False                                                     │
│         no_color = False                                                     │
│          options = ConsoleOptions(                                           │
│                        size=ConsoleDimensions(width=80, height=25),          │
│                        legacy_windows=False,                                 │
│                        min_width=1,                                          │
│                        max_width=80,                                         │
│                        is_terminal=False,                                    │
│                        encoding='utf-8',                                     │
│                        max_height=25,                                        │
│                        justify=None,                                         │
│                        overflow=None,                                        │
│                        no_wrap=False,                                        │
│                        highlight=None,                                       │
│                        markup=None,                                          │
│                        height=None                                           │
│                    )                                                         │
│            quiet = False                                                     │
│           record = False                                                     │
│         safe_box = True                                                      │
│             size = ConsoleDimensions(width=80, height=25)                    │
│        soft_wrap = False                                                     │
│           stderr = False                                                     │
│            style = None                                                      │
│         tab_size = 8                                                         │
│            width = 80                                                        │
╰──────────────────────────────────────────────────────────────────────────────╯
platform="Linux"
WindowsConsoleFeatures(vt=False, truecolor=False)
rich==10.15.1
@nicholaswold nicholaswold changed the title [BUG] Live Progress Bars in Jupyter Notebooks Double-Render [BUG] Live Progress Bars Double-Render in Jupyter Notebooks Dec 3, 2021
@christina-yun
Copy link

Narrowing this down:

Was able to replicate the bug reported here and was able to narrow it down to differences between 10.15.0 and 10.15.1

All version of rich from 10.13.0 through 10.14 didn't have the double render.

Looking at the pull request that got merged, the code that was merged references thread safety. It might be some kind of race condition between multiple threads.

@willingc
Copy link

willingc commented Dec 8, 2021

@christina-yun @nicholaswold Can you check if @willmcgugan's recent fix released as 10.15.2 resolves the behavior that we have seen on 10.15.1?

Thanks Will for a great library!

@christina-yun
Copy link

@willingc - Thank you for the suggestion. I went ahead and tested 10.15.2 and it still has the same issue as 10.15.1 that @nicholaswold and I were able to replicate yesterday.
Screen Shot 2021-12-08 at 9 15 34 AM

@willmcgugan
Copy link
Collaborator

Thanks for narrowing this down. I'll take a look soon.

@willmcgugan
Copy link
Collaborator

I think I have a fix for that. Please give 10.15.3a1 a try.

There are also changes there to workaround issues with thread-safety in Jupyter. So I'd appreciate it if you could try it against any code with progress bars.

@willingc
Copy link

The fix looks like it works for the originally reported example and another notebook with some progress bars. Thanks @willmcgugan. Will let you know if I see anything else.

@willmcgugan
Copy link
Collaborator

That's in 10.16.0 now

@github-actions
Copy link

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 5, 2022
10.16.2

Fixed

Fixed @ not being escaped in markup

10.16.1

Fixed

Fixed issues with overlapping tags Textualize/rich#1755

10.16.0

Fixed

Double print of progress bar in Jupyter Textualize/rich#1737

Added

Added Text.markup property Textualize/rich#1751
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants