-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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] Lines are not properly overwritten in multiline Live panels from within a Jupyter cell #2929
Comments
To help you I will need example code to reproduce the issue. It would also help if you made an attempt to fill in the issue template. |
@willmcgugan I have added the relevant information from the template. This case is a bit tricky because rich runs from a shell that is being piped within a notebook cell. I have tested some other things to narrow the issue and it only happens with multiline Here is something that works: Cell 1 CODE = """
import time
from rich.progress import track
from rich.console import Console
console = Console()
for i in track(range(20), description="Processing...", console=console):
time.sleep(1) # Simulate work being done
"""
with open('./test-rich.py', 'w') as f:
f.write(CODE) Cell 2
Here is something that does not work: Cell 1 CODE = """
import time
from rich.progress import Progress
with Progress() as progress:
task1 = progress.add_task("[red]Downloading...", total=1000)
task2 = progress.add_task("[green]Processing...", total=1000)
while not progress.finished:
progress.update(task1, advance=0.5)
progress.update(task2, advance=0.3)
time.sleep(0.02)
"""
with open('./test-rich.py', 'w') as f:
f.write(CODE) Cell 2
I am trying to upload a notebook but GitHub does not let me do so from an issue. |
As another reference I am having similar issues with multi line Live displays when the python program is piped into something else that might also print into stderr. I expect to see the error messages from the second command but they are swallowed by the Live render refresh. The related code in the I am of course ready to understand that there is no solution to this problem, in which case I will just add some kind of flag to my CLI forcing complex progress bar on a single line when people need to deal with piping jupyter cells. |
Here is an example of piped stderr print swallowing: one.py import time
from rich.console import Console
from rich.progress import Progress
console = Console(stderr=True)
with Progress(console=console) as progress:
task1 = progress.add_task("[red]Downloading...", total=1000)
# task2 = progress.add_task("[green]Processing...", total=1000)
while not progress.finished:
progress.update(task1, advance=0.5)
progress.update(task2, advance=0.3)
time.sleep(0.02) two.py import time
import sys
time.sleep(3)
print('There was an error', file=sys.stderr)
sys.exit(1) Command to run python one.py | python two.py |
I develop a CLI tool and display complex progress bars using a rich Live panel. A lot of people are using the CLI tool directly from jupyter notebook cells using the
!
sigil e.g.:This is what I observe:
The lines are not properly replaced and the progress bar rolls on.
I know this is a strange thing to ask but I cannot find a way around this. The console properly detects the shell env and the colors work properly.
is_terminal
andis_interactive
isTrue
from within the cli program. If Iforce_jupyter=True
if fails and this is expected of course.tqdm
does not have this problem so I guess it revolves around the way lines are erased or replaced at the lowest level and maybe it cannot be safely done without some performance compromise.Sorry if I did not find the proper solution by scouting the different console kwargs/docs etc.
Platform
The text was updated successfully, but these errors were encountered: