Skip to content

Commit 607035e

Browse files
bdbarnettclaude
andcommitted
fix(simulator): show a banner, not a traceback, when the REPL is output-only
PyScript's input() raises on the main thread, so code.interact() dies on its first prompt and Pyodide's REPL pane filled with a traceback -- the run looked broken when in fact the install, the demo and the display had all succeeded. Catch that one failure and print what is actually true: the script finished and this runtime's REPL is output-only. Any other exception still reports normally through _report(). Verified under Playwright: the Pyodide pane now ends with the 3.14.2 banner and the notice, after PSDisplay initialises and the LVGL demo draws. This is cosmetic only. Making the Pyodide REPL genuinely interactive still needs one of the two parity options: make psdisplay worker-safe (it stores a Python object on the canvas element, which cannot cross the worker boundary), or drive an InteractiveConsole from xterm's onData the way sim.lvgl.io feeds characters into MicroPython. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 6c21515 commit 607035e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

simulator/index.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,21 @@
282282

283283
import code
284284

285-
code.interact(local=globals())
285+
try:
286+
code.interact(local=globals())
287+
except Exception as exc:
288+
# PyScript's input() raises on the main thread, so code.interact() dies on
289+
# its first prompt and Pyodide's REPL pane would otherwise show a traceback
290+
# instead of a banner. The runtime stays on the main thread on purpose:
291+
# a worker would fix input(), but psdisplay stores a Python object on the
292+
# canvas element, and a PyProxy cannot cross the worker boundary.
293+
if "input()" in str(exc):
294+
print()
295+
print("--- Script finished. This runtime's REPL is output-only. ---")
296+
print("Switch to MicroPython for an interactive prompt, or press RESET")
297+
print("to run your edited code again.")
298+
else:
299+
_report(exc)
286300
</template>
287301

288302
<!-- Toast Notification -->

0 commit comments

Comments
 (0)