fix(ui): force stdlib asyncio policy so 3-D Twin tab works under uvloop#17
Merged
Conversation
`make ui` crashed every time it tried to render the 3-D Twin tab: Process Process-1: ... ValueError: Can't patch loop of type <class 'uvloop.Loop'> uvicorn ships uvloop as a transitive dependency of Streamlit. If the parent Streamlit process's event-loop policy is uvloop's, `multiprocessing.Process` (forked by stpyvista's trame backend to render the 3-D scene) inherits it. The subprocess then calls `asyncio.run` → `nest_asyncio2._patch_loop`, which only knows how to patch stdlib loops, and bails on `uvloop.Loop`. Fix: - Reset `asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())` at app import time. Streamlit's tornado server is unaffected; the child process now spawns a stdlib loop that nest_asyncio2 can patch. - Wrap the `stpyvista(...)` call in try/except so any future backend crash degrades to a clear warning + an `st.exception` panel rather than a silent subprocess traceback, and the rest of the tab (sliders, compliance badges) stays interactive. No other code paths touched; tests unaffected. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
`make ui` crashed every time the 3-D Twin tab tried to render:
```
Process Process-N:
...
ValueError: Can't patch loop of type <class 'uvloop.Loop'>
```
Root cause
uvicorn ships uvloop as a transitive dependency of Streamlit. If the parent Streamlit process's event-loop policy is uvloop's, `multiprocessing.Process` (forked by stpyvista's trame backend to render the 3-D scene) inherits it. The subprocess then calls `asyncio.run` → `nest_asyncio2._patch_loop`, which only knows how to patch stdlib loops, and bails on `uvloop.Loop`.
Fix
Test plan
🤖 Generated with Claude Code