Open Baa14453 opened 4 months ago
A simple way to avoid this would be to move the with progress as progress_bar
contextmanager to outside of the main while True
loop. This avoids invoking the context manager multiple times. Here is a modified version of your minimal code snippet that works as you describe on my machine (WSL2):
from rich.progress import Progress
import asyncio
async def meow(progress_bar):
task = progress_bar.add_task("Meowing...", total=10)
meows = 0
meow_total = 3
meow_increase = 1
while meows < meow_total:
progress_bar.update(task, advance=meow_total / meow_increase)
meows += meow_increase
await asyncio.sleep(1)
progress_bar.remove_task(task)
progress = Progress(transient=True)
with progress as progress_bar:
while True:
asyncio.run(meow(progress_bar))
Describe the bug
Hi, I'm using asyncio where two independent functions might add a progress bar at any time and they will progress independently. Because of this, I can't use Progress in a context manager such that it destroys the object when the progress is done, instead I am initialising the object and passing it through to both functions at their initialisation.
I didn't want any leftover progress bars to remain, so I delete them on completion by calling remove_task. I then ran into this problem, while the task is removed, either the space it occupied remains, or add_task automatically attempts to compensate for another progress bar that it thinks exists above it, and adds a newline. The result is the same, as time goes on the progress bars descend further and further down, I've recorded a gif to demonstrate:
I've also put together the minimal code to recreate this:
Platform
Click to expand
What platform (Win/Linux/Mac) are you running on? What terminal software are you using? Ubuntu 22.04, Gnome Terminal and the VSCodium / VSCode terminal. If you're using Rich in a terminal: ``` ╭─────────────────────────