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: just exit on non-interactive terminals (#5126)
Myles Scolnick0a2f69d690dc
diff --git a/marimo/_server/api/interrupt.py b/marimo/_server/api/interrupt.pyindex fed003e559..8a21ece8e5 100644--- a/marimo/_server/api/interrupt.py+++ b/marimo/_server/api/interrupt.py@@ -3,6 +3,7 @@ from __future__ import annotationsimport asyncioimport signal+import sysimport timefrom typing import Callable@@ -60,6 +61,11 @@ class InterruptHandler:self.shutdown()return+ # If not in an interactive terminal, just exit+ if not sys.stdin.isatty():+ self.shutdown()+ return+response = input(f"\r{TAB}Are you sure you want to quit? (y/n): ")diff --git a/tests/_server/api/test_interrupt.py b/tests/_server/api/test_interrupt.pyindex b63c2e669a..750c57a476 100644--- a/tests/_server/api/test_interrupt.py+++ b/tests/_server/api/test_interrupt.py@@ -2,12 +2,15 @@from __future__ import annotationsimport asyncio+from typing import Anyfrom unittest.mock import Mock, patchfrom marimo._server.api.interrupt import InterruptHandler-async def test_interrupt_handler() -> None:+@patch("sys.stdin.isatty", return_value=True)+async def test_interrupt_handler(patch_isatty: Any) -> None:+ del patch_isattyshutdown_mock = Mock()# Create an instance of InterruptHandler with quiet mode disabled@@ -36,3 +39,25 @@ async def test_interrupt_handler() -> None:# Assert that the shutdown callable was not calledshutdown_mock.assert_not_called()+++@patch("sys.stdin.isatty", return_value=False)+async def test_interrupt_handler_non_interactive_terminal(+ patch_isatty: Any,+) -> None:+ del patch_isatty+ shutdown_mock = Mock()++ # Create an instance of InterruptHandler with quiet mode disabled+ interrupt_handler = InterruptHandler(quiet=False, shutdown=shutdown_mock)++ # Register the interrupt handler+ interrupt_handler.register()++ # Simulate Ctrl+C signal+ interrupt_handler.loop.call_soon(interrupt_handler._interrupt_handler)+ await asyncio.sleep(0) # Let the event loop process the signal++ # Assert that the shutdown callable was called immediately+ # without prompting for user input+ shutdown_mock.assert_called_once()