microbit-foundation / python-editor-v3

Micro:bit Educational Foundation Python Editor V3
https://python.microbit.org
MIT License
57 stars 36 forks source link

[Simulator] Calling reset() in MicroPython program asserts in sim #899

Closed microbit-matt-hillsdon closed 2 years ago

microbit-matt-hillsdon commented 2 years ago

Running

from microbit import *

reset()

in the sim results in the following logged error:

Uncaught (in promise) Error: Already started!
    at WebAssemblyOperations.start (micropython.js:306:15)
    at BoardUI.start (micropython.js:1783:23)
    at BoardUI.reset (micropython.js:1793:12)

There are likely other negative consequences.

microbit-matt-hillsdon commented 2 years ago

Recent changes mean this now restarts OK. In the demo it seems to work fine. But in the editor we see serial no longer echos what you type (and perhaps is otherwise broken).

However, it works fine with this program:

n = 0
while True:
    n += 1
    print(n)
    sleep(1000)
microbit-matt-hillsdon commented 2 years ago

OK, so this does actually work but it's a little confusing as there's time/opportunity for the sim to print the next REPL prompt. That made me think serial should be working even though it was actually just busy running the program. I think the reset HAL method should throw similarly to the panic case. Then we can handle it in the same way but just restart.

microbit-matt-hillsdon commented 2 years ago

Sim PR that takes the ResetError approach:

https://github.com/microbit-foundation/micropython-microbit-v2-simulator/pull/54

microbit-matt-hillsdon commented 2 years ago

Sim PR merged. Closing.