Skip to content

Ctrl-C during scroll continues to subsequent raised exception #134

Closed
@microbit-matt-hillsdon

Description

@microbit-matt-hillsdon
Contributor

Run this script:

from microbit import *

display.scroll('Takes a while')
raise ValueError(123)

Press Ctrl-C during the scrolling text.

Unexpectedly you see the error message from the ValueError scrolled on the micro:bit.

If the raise line is replaced with print("Here") then the print output doesn't show.
If the scroll is replaced by a sleep then the ValueError does not show.

This behaviour is a bit awkward for the simulator as our stop button sends a Ctrl-C to interrupt the program, but given this behaviour it can be 10s of seconds before it actually stops.

The original code example was more realistic with the ValueError thrown by micro:bit MicroPython API parameter validation.

Activity

dpgeorge

dpgeorge commented on Sep 27, 2022

@dpgeorge
Collaborator

Thanks for the report. This is a strange bug!

The following should fix it, but I need to test it more before merging this fix:

--- a/src/codal_port/drv_display.c
+++ b/src/codal_port/drv_display.c
@@ -67,6 +67,7 @@ STATIC void wait_for_event() {
         // allow CTRL-C to stop the animation
         if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) {
             async_stop();
+            mp_handle_pending(true);
             return;
         }
         microbit_hal_idle();
microbit-matt-hillsdon

microbit-matt-hillsdon commented on Oct 10, 2022

@microbit-matt-hillsdon
ContributorAuthor

@microbit-robert to try this out and update the issue.

microbit-robert

microbit-robert commented on Oct 10, 2022

@microbit-robert

The suggested change above works well and fixes the issue described.

added this to the 2.2 milestone on Oct 17, 2022
modified the milestones: 2.2, 2.1.1 on Oct 19, 2022
dpgeorge

dpgeorge commented on Oct 24, 2022

@dpgeorge
Collaborator

I tested this and checked that all callers of this function can accept it raising an exception.

Implemented in cfe75b2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @dpgeorge@microbit-carlos@microbit-matt-hillsdon@microbit-robert

      Issue actions

        Ctrl-C during scroll continues to subsequent raised exception · Issue #134 · microbit-foundation/micropython-microbit-v2