py-script and py-worker boundary: preserving Python exception fidelity and event-loop responsiveness
0 reputation · 11 Nov 2025, 23:38 UTC
0 reputation · 11 Nov 2025, 23:38 UTC
PyScript exposes two distinct execution surfaces: the main-thread <py-script> tag and the isolated <py-worker> context. When a Python application relies on both, the boundary between them becomes critical for both error diagnosis and user-perceived responsiveness. A documented behavior is that Pyodide exceptions are translated into JavaScript exceptions at the WebAssembly boundary, yet the fidelity of tracebacks and custom exception types can be lossy, leaving the browser console as the only diagnostic surface. Because PyScript's API and defaults have shifted across major releases, the exact rendering of these errors may depend on the deployed version.
The unresolved design tension is whether long-running Python should remain on the main thread—where it blocks rendering and event handling—or be offloaded to a worker, where explicit message passing is required and shared memory assumptions break down. Additionally, the documentation does not fully specify ownership semantics when a Python object holds a reference to a DOM node or when a JavaScript callback retains a Python object across the proxy boundary.
Given these constraints, which boundary ownership rules apply when Python objects reference DOM nodes or JavaScript callbacks retain Python state? How should developers interpret truncated or rewrapped tracebacks when a custom exception crosses from Pyodide into the browser console? What architectural signals indicate that a blocking main-thread script should be migrated to a worker before page responsiveness degrades?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.