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: stdout and stderr should not be stoppable by users (#5955)
Akshay Agrawal6e4010e6716d
diff --git a/marimo/_messaging/streams.py b/marimo/_messaging/streams.pyindex 11d69696f2..4a1e1e628e 100644--- a/marimo/_messaging/streams.py+++ b/marimo/_messaging/streams.py@@ -212,7 +212,7 @@ class ThreadSafeStdout(Stdout):self._original_fd = sys.stdout.fileno()self._watcher = Watcher(self)- def stop(self) -> None:+ def _stop(self) -> None:self._watcher.stop()def fileno(self) -> int:@@ -278,7 +278,7 @@ class ThreadSafeStderr(Stderr):self._original_fd = sys.stderr.fileno()self._watcher = Watcher(self)- def stop(self) -> None:+ def _stop(self) -> None:self._watcher.stop()def fileno(self) -> int:diff --git a/marimo/_messaging/types.py b/marimo/_messaging/types.pyindex baa7d10d7e..3e4ac42196 100644--- a/marimo/_messaging/types.py+++ b/marimo/_messaging/types.py@@ -36,6 +36,7 @@ class NoopStream(Stream):pass+# These streams are not stoppable by users (we don't implement stop).class Stdout(io.TextIOBase):name = "stdout"@@ -48,7 +49,7 @@ class Stdout(io.TextIOBase):def write(self, __s: str) -> int:return self._write_with_mimetype(__s, mimetype="text/plain")- def stop(self) -> None:+ def _stop(self) -> None:"""Tear down resources, if any."""pass@@ -65,7 +66,7 @@ class Stderr(io.TextIOBase):def write(self, __s: str) -> int:return self._write_with_mimetype(__s, mimetype="text/plain")- def stop(self) -> None:+ def _stop(self) -> None:"""Tear down resources, if any."""pass@@ -73,6 +74,6 @@ class Stderr(io.TextIOBase):class Stdin(io.TextIOBase):name = "stdin"- def stop(self) -> None:+ def _stop(self) -> None:"""Tear down resources, if any."""passdiff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex fb5c1a20da..18face7c23 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -646,11 +646,11 @@ class Kernel:def teardown(self) -> None:"""Teardown resources owned by the kernel."""if self.stdout is not None:- self.stdout.stop()+ self.stdout._stop()if self.stderr is not None:- self.stderr.stop()+ self.stderr._stop()if self.stdin is not None:- self.stdin.stop()+ self.stdin._stop()self.stream.stop()if self.module_watcher is not None:diff --git a/tests/_messaging/test_types.py b/tests/_messaging/test_types.pyindex 16dcf353a0..4a6e2be556 100644--- a/tests/_messaging/test_types.py+++ b/tests/_messaging/test_types.py@@ -83,16 +83,21 @@ class TestStdoutStderr:stderr = self.MockStderr()assert stderr.name == "stderr"+ def test_not_stoppable(self) -> None:+ stdout = self.MockStdout()+ assert not hasattr(stdout, "stop")+ stderr = self.MockStderr()+ assert not hasattr(stderr, "stop")+class TestStdin:def test_stdin_name(self) -> None:stdin = Stdin()assert stdin.name == "stdin"- def test_stdin_stop(self) -> None:+ def test_not_stoppable(self) -> None:stdin = Stdin()- # Should not raise any exceptions- stdin.stop()+ assert not hasattr(stdin, "stop")class TestKernelMessage: