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
Catch/log exception when writing to pipe (#246)
Akshay Agrawala5623b88c805
diff --git a/marimo/_messaging/streams.py b/marimo/_messaging/streams.pyindex ebcdebcf46..7e8c2b073d 100644--- a/marimo/_messaging/streams.py+++ b/marimo/_messaging/streams.py@@ -7,9 +7,12 @@ from collections import dequefrom multiprocessing.connection import Connectionfrom typing import Any, Optional+from marimo import _loggersfrom marimo._ast.cell import CellId_tfrom marimo._messaging.console_output_worker import ConsoleMsg, buffered_writer+LOGGER = _loggers.marimo_logger()+# Byte limits on outputs. Limits exist for two reasons:## 1. We use a multiprocessing.Connection object to send outputs from@@ -56,7 +59,12 @@ class Stream:def write(self, op: str, data: dict[Any, Any]) -> None:with self.stream_lock:- self.pipe.send((op, data))+ try:+ self.pipe.send((op, data))+ except OSError as e:+ # Most likely a BrokenPipeError, caused by the+ # server process shutting down+ LOGGER.debug("Error when writing (op: %s) to pipe: %s", op, e)class Stdout:diff --git a/marimo/_runtime/functions.py b/marimo/_runtime/functions.pyindex 752e8f2d7d..e86e9d6a35 100644--- a/marimo/_runtime/functions.py+++ b/marimo/_runtime/functions.py@@ -16,6 +16,7 @@ T = TypeVar("T")@dataclasses.dataclassclass EmptyArgs:"""Utility type for functions that take no arguments."""+...diff --git a/marimo/_server/server.py b/marimo/_server/server.pyindex 5ae99ee1a4..ed83d0d96f 100644--- a/marimo/_server/server.py+++ b/marimo/_server/server.py@@ -63,6 +63,8 @@ def shutdown(with_error: bool = False) -> None:)print()mgr.shutdown()+ # TODO(akshayka): This method raises an exception sometimes.+ # debug, or just wrap in a try/except since we're on our way out anyway ...tornado.ioloop.IOLoop.current().stop()if with_error:sys.exit(1)