marimo-team / marimo

A reactive notebook for Python — run reproducible experiments, execute as a script, deploy as an app, and version with git.
https://marimo.io
Apache License 2.0
5.35k stars 156 forks source link

WebSocketDisconnect (kernel not found) when using marimo edit #1622

Closed switchball closed 1 week ago

switchball commented 2 weeks ago

Describe the bug

Hi all, I'm using conda 4.8.1 and create a Python 3.9.18 environment, on MacOS 10.15.7. After run pip install marimo, run marimo tutorial intro it works and show the notebook.

But if I run marimo edit, it open explorer then show kernel not found, the terminal outputs

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 332, in asgi_send
    await self.send(data)  # type: ignore[arg-type]
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 647, in send
    await self.write_frame(True, opcode, data)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1209, in write_frame
    await self.drain()
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 1198, in drain
    await self.ensure_open()
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 939, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/websockets.py", line 97, in send
    await self._send(message)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/_exception_handler.py", line 50, in sender
    await send(message)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 83, in send_wrapper
    await send(message)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 345, in asgi_send
    raise ClientDisconnected from exc
uvicorn.protocols.utils.ClientDisconnected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/uvicorn/protocols/websockets/websockets_impl.py", line 244, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)  # type: ignore[func-returns-value]
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/errors.py", line 151, in __call__
    await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/marimo/_server/api/auth.py", line 215, in __call__
    return await super().__call__(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/sessions.py", line 85, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/authentication.py", line 49, in __call__
    await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/cors.py", line 77, in __call__
    await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/marimo/_server/api/middleware.py", line 64, in __call__
    return await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 485, in handle
    await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 373, in handle
    await self.app(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 96, in app
    await wrap_app_handling_exceptions(app, session)(scope, receive, send)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/routing.py", line 94, in app
    await func(session)
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 76, in websocket_endpoint
    await WebsocketHandler(
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 386, in start
    await self.future
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/marimo/_server/api/endpoints/ws.py", line 318, in listen_for_messages
    await self.websocket.send_text(
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/websockets.py", line 188, in send_text
    await self.send({"type": "websocket.send", "text": data})
  File "/Users/art9/anaconda3/envs/py39/lib/python3.9/site-packages/starlette/websockets.py", line 100, in send
    raise WebSocketDisconnect(code=1006)
starlette.websockets.WebSocketDisconnect
        Are you sure you want to quit? (y/n): ^C

I tried copy the intro.py to workspace folder and run marimo edit intro.py, it does not work.

I am confused about why tutorial intro command works, but edit command failed. Is there a difference and maybe related to my python env?

Environment

{ "marimo": "0.6.19", "OS": "Darwin", "OS Version": "19.6.0", "Processor": "i386", "Python Version": "3.9.18", "Binaries": { "Browser": "115.0.5790.170", "Node": "v18.12.1" }, "Requirements": { "click": "8.1.7", "importlib-resources": "6.4.0", "jedi": "0.19.1", "markdown": "3.6", "pymdown-extensions": "10.8.1", "pygments": "2.17.2", "tomlkit": "0.12.5", "uvicorn": "0.30.1", "starlette": "0.37.2", "websockets": "12.0", "typing-extensions": "4.10.0", "black": "24.2.0" } }

Code to reproduce

No response

switchball commented 2 weeks ago

Oh, I had solved the problem by running python -m mario edit, it maybe due to a python library dependency.

akshayka commented 2 weeks ago

@switchball -- are you still seeing this problem?

akshayka commented 1 week ago

@switchball Version 0.6.22 should fix this issue. Please reopen if you see it again. Thanks!