Skip to content

pressing Ctrl-C breaks time.sleep() until reboot #2865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xobs opened this issue May 7, 2020 · 9 comments
Closed

pressing Ctrl-C breaks time.sleep() until reboot #2865

xobs opened this issue May 7, 2020 · 9 comments

Comments

@xobs
Copy link

xobs commented May 7, 2020

Description

Pressing Ctrl-C to interrupt time.sleep() will cause time.sleep() to instantaneously return on NRF until the board is reset.

Steps to reproduce

In the REPL, run:

import time
time.sleep(100)

While it's sleeping, press Ctrl-C. The REPL will come back. Then run:

time.sleep(100)

The REPL will return instantly.

Workaround

Performing a soft- or hard-reboot re-initializes the sleep timer and gets it working again.

@tannewt tannewt added this to the 5.x.x - Bug Fixes milestone May 7, 2020
@tannewt
Copy link
Member

tannewt commented May 7, 2020

Is this on both nRF52840 and nRF52833? Please let us know what boards you've found this on. Thanks!

@dhalbert
Copy link
Collaborator

dhalbert commented May 7, 2020

I see this on Feather nRF52840.

@dhalbert
Copy link
Collaborator

dhalbert commented May 7, 2020

This is not just nRF. I see the same thing on Metro M0.

@dhalbert dhalbert changed the title NRF: pressing Ctrl-C breaks time.sleep() until reboot pressing Ctrl-C breaks time.sleep() until reboot May 7, 2020
@dhalbert
Copy link
Collaborator

dhalbert commented May 7, 2020

This broke somewhere between 3.1.2 and 4.1.2.
EDIT: narrowed to between 4.0.2 and 4.1.0-beta.1. Now I'm bisecting (had to install python2 as python to build)

@dhalbert
Copy link
Collaborator

dhalbert commented May 7, 2020

Commit causing the issue is ea760c0: "Turn on MICROPY_OPT_COMPUTED_GOTO for 5x CPU-bound speedup". So probably there's something wrong with how MP_STATE_VM(mp_pending_exception) is handled when MICROPY_OPT_COMPUTED_GOTO is turned on in the VM.

When time.sleep(100) is ctrl-c'd in a good build, you see

>>> time.sleep(100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyboardInterrupt: 

In a bad build, you just see

>>> time.sleep(100)   # ctrl-c typed
>>>

@dhalbert
Copy link
Collaborator

dhalbert commented May 8, 2020

This problem does not occur in current micropython even when MICROPY_OPT_COMPUTED_GOTO = 1.

I compared our py/vm.c with micropython's, because MICROPY_OPT_COMPUTED_GOTO is only significant in that file. There are differences in exception handling based on the flag.

Really interestingly, this micropython commit, which is a minor speedup, micropython@869024d, changes

    #define DISPATCH() break

to

    #define DISPATCH() goto dispatch_loop

If I make that same change in our py/vm.c, then I can reproduce the problem even when MICROPY_OPT_COMPUTED_GOTO = 0. I haven't been able to track down other micropython changes yet that are causing this problem not to occur on micropython, though I will go back a year or two at a time in micropython in ports with computed goto turned on and see what happens. It's fishy in the previous comment that the interrupt doesn't get printed.

@dhalbert
Copy link
Collaborator

dhalbert commented May 8, 2020

Aha: #1092

@kevinjwalters
Copy link

Is this a dupe of #2691 ?

#2689 features more control-c / interrupt woes.

@tannewt
Copy link
Member

tannewt commented Jul 14, 2020

This is fixed by #3043. Thanks @DavePutz!

@tannewt tannewt closed this as completed Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants