Fail loudly instead of hanging forever when no frontend connects (#281) - #292
Merged
Conversation
…#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 vpythonbusy-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
while (not wsConnected): sleep(0.1)at import time inwith_notebook.pybecomes a bounded wait — default 30 s, overridable viaVPYTHON_CONNECT_TIMEOUTfor genuinely slow first-runs (nbextension transfer on cold environments).RuntimeErrorwith a message that:VSCODE_PID/VSCODE_CWD, Colab viaCOLAB_RELEASE_TAG/COLAB_GPU, or a generic explanation),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