Skip to content

Fail loudly instead of hanging forever when no frontend connects (#281) - #292

Merged
sspickle merged 1 commit into
masterfrom
fix/281-frontend-connect-timeout
Aug 16, 2026
Merged

Fail loudly instead of hanging forever when no frontend connects (#281)#292
sspickle merged 1 commit into
masterfrom
fix/281-frontend-connect-timeout

Conversation

@sspickle

Copy link
Copy Markdown
Contributor

Addresses the worst half of #281: in any notebook frontend that never runs vpython's injected JavaScript — VS Code notebooks and Google Colab being the common cases — import vpython busy-waited forever on the websocket handshake, silently hanging the kernel.

This does not make VPython work in those environments (that's the renderer/adapter work, tracked separately) — it converts an indefinite silent hang into a prompt, actionable error.

What changes

  • The unbounded while (not wsConnected): sleep(0.1) at import time in with_notebook.py becomes a bounded wait — default 30 s, overridable via VPYTHON_CONNECT_TIMEOUT for genuinely slow first-runs (nbextension transfer on cold environments).
  • On timeout it raises RuntimeError with a message that:
    • names the detected environment (VS Code via VSCODE_PID/VSCODE_CWD, Colab via COLAB_RELEASE_TAG/COLAB_GPU, or a generic explanation),
    • says where VPython does work (Jupyter Notebook / JupyterLab in a browser),
    • links this issue,
    • and mentions the timeout override.
  • The wait lives in a new pure-python helper (vpython/_frontend_wait.py) with injected clock/sleep/environ, so it's fully unit-tested (6 new tests; suite now 14) without any kernel or websocket machinery.

Not changed

Normal Jupyter/Lab flows are unaffected — the wait still returns the moment the frontend connects, typically within a couple of seconds.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G7y9rTA1r8r8EhEnPSQenR

…#281)

The notebook path busy-waited unboundedly on the websocket handshake at
import time. Frontends that never run vpython's injected JavaScript — VS
Code notebooks, Google Colab — therefore hung the kernel silently inside
'import vpython'. Now a bounded wait (default 30s, VPYTHON_CONNECT_TIMEOUT
to override) raises a RuntimeError that names the detected environment
(VS Code / Colab / generic), points at working environments, and links the
tracking issue. Pure-python helper, fully unit tested.
@sspickle
sspickle merged commit 3254f6e into master Aug 16, 2026
13 checks passed
@sspickle
sspickle deleted the fix/281-frontend-connect-timeout branch August 16, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant