A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: flush progress text changes immediately (#11337)
Kiran Gadhave2dc443678a11
diff --git a/marimo/_plugins/stateless/status/_progress.py b/marimo/_plugins/stateless/status/_progress.pyindex f8d03f5931..55be8031c4 100644--- a/marimo/_plugins/stateless/status/_progress.py+++ b/marimo/_plugins/stateless/status/_progress.py@@ -90,6 +90,9 @@ class _Progress(Html):"Progress indicators cannot be updated after exiting ""the context manager that created them. ")+ text_changed = (title is not None and title != self.title) or (+ subtitle is not None and subtitle != self.subtitle+ )self.current += incrementif title is not None:self.title = title@@ -97,7 +100,10 @@ class _Progress(Html):self.subtitle = subtitleself._text = self._get_text()- self.debounced_flush()+ if text_changed:+ output.flush()+ else:+ self.debounced_flush()@debounce(0.15)def debounced_flush(self) -> None:@@ -309,8 +315,8 @@ class progress_bar(Generic[S]):arguments `increment` (defaults to `1`), `title`,and `subtitle`.- For performance reasons, the progress bar is only updated in the UI- every 150ms.+ For performance reasons, numeric progress updates are rate limited to+ once every 150ms. Title and subtitle changes appear immediately.Args:collection (Union[Collection[S], Iterator[S], AsyncIterable[S]], optional): Optional collection to iterate over.diff --git a/tests/_plugins/stateless/status/test_progress.py b/tests/_plugins/stateless/status/test_progress.pyindex a9e2d6a3c2..6c2a5bb0da 100644--- a/tests/_plugins/stateless/status/test_progress.py+++ b/tests/_plugins/stateless/status/test_progress.py@@ -13,6 +13,8 @@ from marimo._plugins.stateless.status._progress import (spinner,)from marimo._runtime.context.types import runtime_context_installed+from marimo._types.ids import CellId_t+from tests.conftest import MockedKernelif TYPE_CHECKING:from collections.abc import AsyncIterator@@ -140,6 +142,45 @@ def test_update_progress_closed(mock_flush: Any) -> None:mock_flush.assert_called_once()[email protected]("kind", ["progress_bar", "spinner"])[email protected]("field", ["title", "subtitle"])+def test_rapid_text_updates(+ mocked_kernel: MockedKernel, kind: str, field: str+) -> None:+ with mocked_kernel.k._install_execution_context(cell_id=CellId_t("0")):+ with patch("time.time", return_value=time.time()):+ indicator: progress_bar[int] | spinner = (+ progress_bar(total=5) if kind == "progress_bar" else spinner()+ )+ with indicator as status:+ for text in ["first", "second", "third"]:+ status.update(+ title=text if field == "title" else None,+ subtitle=text if field == "subtitle" else None,+ )+ outputs = [+ msg.output.data+ for msg in mocked_kernel.stream.cell_notifications+ if msg.output is not None+ ]+ assert f"data-{field}='"third"'" in outputs[-1]+++ ("title", "subtitle"), [(None, None), ("fixed", None), (None, "fixed")]+)+@patch("marimo._runtime.output._output.flush")+def test_numeric_updates_remain_rate_limited(+ mock_flush: Any, title: str | None, subtitle: str | None+) -> None:+ with patch("time.time", return_value=time.time()):+ with progress_bar(total=100, title=title, subtitle=subtitle) as bar:+ bar.update(title=title, subtitle=subtitle)+ mock_flush.reset_mock()+ bar.update(title=title, subtitle=subtitle)+ mock_flush.assert_not_called()++def test_spinner_without_context():assert runtime_context_installed() is False