Describe the bug
I noticed that in Jupyter notebooks, any Live environment that is run after a first one has been executed before doesn't get automatic refreshes. I don't see this happening in the terminal, and I cannot see any hint in the documentation or Issues on how to fix this.
For example, let's consider this code:
import time
from rich.text import Text
from rich.live import Live
from rich.progress import Spinner
from rich.console import Group
# Define a spinner and a text, and group them together
spinner = Spinner(name="dots", text="Running...", style="green", speed=1)
text = Text("Blah")
group = Group(text, spinner)
# Run a Live environment and append text after each iteration
with Live(group) as live:
for _ in range(5):
time.sleep(1)
text.append_text(Text(" blah"))
# Run the same task again (with a new Live)
with Live(group) as live:
for _ in range(5):
time.sleep(1)
text.append_text(Text(" blah"))
If I run this in the terminal, I see both Live environments working as expected: the text gets new appended words after each iteration, and the spinner works great in both cases:
Blah blah blah blah blah blah
⠹ Running...
Blah blah blah blah blah blah blah blah blah blah blah
⠴ Running...
But when trying to run the same in a notebook, the second run doesn't automatically refresh: it shows just the initial state of the Group for 5 seconds, and then the cell finishes its execution, without any update in the output.
I'm using JupyterLab here, but I also notice the same behaviour in Jupyter Notebooks.
A few comments
I know that I could run live.refresh() after each iteration, and that will partially solve the issue. But, I intentionally added a spinner here, because such trick will not force the spinner to refresh in higher rate.
I'm suspecting this issue might be coming from the underlying ipywidget that Live creates, but I'm not sure if that's the case, and I'm not so familiar with ipywidgets to debug it yet.
I see the same behaviour even when using transient=True. I could provide a minimal example if required.
Lastly, thanks a lot for developing Rich!
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Linux. I'm using Gnome Terminal and JupyterLab.
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.
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 0x7f2ea866d180> │
│ height = 100 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = False │
│ is_jupyter = True │
│ is_terminal = False │
│ 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=False, │
│ 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 ───────╮
│ { │
│ 'CLICOLOR': '1', │
│ 'COLORTERM': 'truecolor', │
│ 'COLUMNS': None, │
│ 'JPY_PARENT_PID': '26737', │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'LINES': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': 'tmux', │
│ 'TERM': 'xterm-color', │
│ 'TTY_COMPATIBLE': None, │
│ 'TTY_INTERACTIVE': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"
Describe the bug
I noticed that in Jupyter notebooks, any
Liveenvironment that is run after a first one has been executed before doesn't get automatic refreshes. I don't see this happening in the terminal, and I cannot see any hint in the documentation or Issues on how to fix this.For example, let's consider this code:
If I run this in the terminal, I see both
Liveenvironments working as expected: the text gets new appended words after each iteration, and the spinner works great in both cases:But when trying to run the same in a notebook, the second run doesn't automatically refresh: it shows just the initial state of the
Groupfor 5 seconds, and then the cell finishes its execution, without any update in the output.I'm using JupyterLab here, but I also notice the same behaviour in Jupyter Notebooks.
A few comments
I know that I could run
live.refresh()after each iteration, and that will partially solve the issue. But, I intentionally added a spinner here, because such trick will not force the spinner to refresh in higher rate.I'm suspecting this issue might be coming from the underlying ipywidget that
Livecreates, but I'm not sure if that's the case, and I'm not so familiar with ipywidgets to debug it yet.I see the same behaviour even when using
transient=True. I could provide a minimal example if required.Lastly, thanks a lot for developing Rich!
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using?
Linux. I'm using Gnome Terminal and JupyterLab.
I may ask you to copy and paste the output of the following commands. It may save some time if you do it now.