Code: Select all
import uasyncio as asyncio
import machine
def set_global_exception():
def handle_exception(loop, context):
import sys
sys.print_exception(context["exception"])
sys.exit()
loop = asyncio.get_event_loop()
loop.set_exception_handler(handle_exception)
async def blink_task():
led = machine.Pin(25, machine.Pin.OUT)
while True:
led.toggle()
await asyncio.sleep_ms(150)
async def main():
set_global_exception() # Debug aid
blinky = asyncio.create_task(blink_task())
await blinky
try:
asyncio.run(main())
finally:
asyncio.new_event_loop()
What could be the reason for that?
EDIT: I think I found the main reason, being not reading the docs as thoroughly as I should. The program restarts thanks to the *finally* clause. If I remove the *asyncio.new_event_loop()*, I get the REPL when resetting the device again.
EDIT 2: The problem persists - after disconnecting the board, it's impossible to connect to REPL again.