Skip to content

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.

fix: skip conencting to terminal in windows (#7861)

Myles Scolnickfb3696a3bd04
diff --git a/frontend/src/components/editor/chrome/state.ts b/frontend/src/components/editor/chrome/state.ts
index f98922fa9a..0c5958fd4d 100644
--- a/frontend/src/components/editor/chrome/state.ts
+++ b/frontend/src/components/editor/chrome/state.ts
@@ -68,7 +68,7 @@ const storage = new ZodLocalStorage<ChromeState>(
selectedDeveloperPanelTab: z
.string()
.optional()
- .default("terminal")
+ .default("errors")
.transform((v) => v as PanelType),
}),
initialState,
@@ -79,7 +79,7 @@ function initialState(): ChromeState {
selectedPanel: "variables", // initial panel
isSidebarOpen: false,
isDeveloperPanelOpen: false,
- selectedDeveloperPanelTab: "terminal",
+ selectedDeveloperPanelTab: "errors",
};
}
diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
index 7b3bd887d7..3979a09203 100644
--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx
@@ -355,7 +355,11 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
{Object.entries(SIDEBAR_PANELS).map(([key, Panel]) => (
<LazyActivity
key={key}
- mode={selectedPanel === key ? "visible" : "hidden"}
+ mode={
+ isSidebarOpen && selectedPanel === key
+ ? "visible"
+ : "hidden"
+ }
>
{Panel}
</LazyActivity>
@@ -503,7 +507,9 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {
<LazyActivity
key={key}
mode={
- selectedDeveloperPanelTab === key ? "visible" : "hidden"
+ isDeveloperPanelOpen && selectedDeveloperPanelTab === key
+ ? "visible"
+ : "hidden"
}
>
{Panel}
diff --git a/marimo/_server/api/endpoints/terminal.py b/marimo/_server/api/endpoints/terminal.py
index 23a7569eaf..d0788c4156 100644
--- a/marimo/_server/api/endpoints/terminal.py
+++ b/marimo/_server/api/endpoints/terminal.py
@@ -17,6 +17,7 @@ from marimo import _loggers
from marimo._server.api.deps import AppState
from marimo._server.router import APIRouter
from marimo._session.model import SessionMode
+from marimo._utils.platform import is_pyodide, is_windows
if TYPE_CHECKING:
from collections.abc import Iterable
@@ -323,6 +324,19 @@ async def _cancel_tasks(tasks: Iterable[asyncio.Task[Any]]) -> None:
pass
+def supports_terminal() -> bool:
+ """Whether the current environment supports terminals."""
+ if is_windows() or is_pyodide():
+ return False
+ # Try to import pty to verify it's actually available
+ try:
+ import pty # noqa: F401
+
+ return True
+ except ImportError:
+ return False
+
+
@router.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket) -> None:
app_state = AppState(websocket)
@@ -332,6 +346,12 @@ async def websocket_endpoint(websocket: WebSocket) -> None:
)
return
+ if not supports_terminal():
+ await websocket.close(
+ code=1008, reason="Terminal not supported in this environment"
+ )
+ return
+
try:
await websocket.accept()
LOGGER.debug("Terminal websocket accepted")
@@ -339,17 +359,29 @@ async def websocket_endpoint(websocket: WebSocket) -> None:
LOGGER.error(f"Failed to accept websocket connection: {e}")
return
- import pty
+ # Initialize PTY - wrap in try-except to handle any unexpected failures
+ try:
+ import pty
- child_pid, fd = pty.fork()
- if child_pid == 0:
- # Child process - set up the shell environment
- shell, env = _create_shell_environment()
- cwd = env.get("PWD", os.getcwd())
- _setup_child_process(shell, env, cwd)
+ child_pid, fd = pty.fork()
+ if child_pid == 0:
+ # Child process - set up the shell environment
+ shell, env = _create_shell_environment()
+ cwd = env.get("PWD", os.getcwd())
+ _setup_child_process(shell, env, cwd)
- # Set up cleanup handler
- cleanup_child = _create_process_cleanup_handler(child_pid, fd)
+ # Set up cleanup handler
+ cleanup_child = _create_process_cleanup_handler(child_pid, fd)
+ except Exception as e:
+ LOGGER.error(f"Failed to initialize terminal: {e}")
+ try:
+ if websocket.application_state != WebSocketState.DISCONNECTED:
+ await websocket.close(
+ code=1011, reason="Failed to initialize terminal"
+ )
+ except Exception:
+ pass
+ return
reader_task = asyncio.create_task(_read_from_pty(fd, websocket))
writer_task = asyncio.create_task(_write_to_pty(fd, websocket, child_pid))