Skip to content

Commit 88ae813

Browse files
authored
Fix Rich progress bar flickering by limiting refreshes (#571)
1 parent 7b32304 commit 88ae813

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cubed/diagnostics/rich.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import sys
3+
import time
34
from contextlib import contextmanager
45

56
from rich.console import RenderableType
@@ -18,6 +19,8 @@
1819
from cubed.runtime.pipeline import visit_nodes
1920
from cubed.runtime.types import Callback
2021

22+
REFRESH_PER_SECOND = 10
23+
2124

2225
class RichProgressBar(Callback):
2326
"""Rich progress bar for a computation."""
@@ -50,6 +53,7 @@ def on_compute_start(self, event):
5053
self.logger_aware_progress = logger_aware_progress
5154
self.progress = progress
5255
self.progress_tasks = progress_tasks
56+
self.last_updated = time.time()
5357

5458
def on_compute_end(self, event):
5559
self.logger_aware_progress.__exit__(None, None, None)
@@ -58,8 +62,11 @@ def on_operation_start(self, event):
5862
self.progress.start_task(self.progress_tasks[event.name])
5963

6064
def on_task_end(self, event):
65+
now = time.time()
66+
refresh = now - self.last_updated > (1.0 / REFRESH_PER_SECOND)
67+
self.last_updated = now
6168
self.progress.update(
62-
self.progress_tasks[event.name], advance=event.num_tasks, refresh=True
69+
self.progress_tasks[event.name], advance=event.num_tasks, refresh=refresh
6370
)
6471

6572

0 commit comments

Comments
 (0)