Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

machine.sleep(0) causes a crash #410

Open
deltazita opened this issue Feb 24, 2020 · 1 comment
Open

machine.sleep(0) causes a crash #410

deltazita opened this issue Feb 24, 2020 · 1 comment

Comments

@deltazita
Copy link

machine.sleep(0) causes a crash on LoPy4 with v1.20.1 firmware.

@robert-hh
Copy link
Contributor

robert-hh commented Feb 25, 2020

Confirmed with 1.20.2.rc3 on a FiPy, almost always. A simple fix is to check for values <= 0, and return immediately in that case. Tested and confirmed, it works.

P.S., just in case someone from the Pycom team is taking care of issues: I added these lines to the start of the function mp_obj_t machine_sleep () in esp32/mods/modmachine.c:

    int64_t sleep_time = 1000; // Safe default value, just to silence compiler warnings
    
    if (n_args > 0) {
        sleep_time = (int64_t)mp_obj_get_int_truncated(arg[0]) * 1000;
        if (sleep_time <= 0) {
            return mp_const_none;
        }
    }

And deleted the then obsolete line to set sleep_time a few lines down the row.

amotl pushed a commit to daq-tools/pycom-micropython that referenced this issue Mar 6, 2020
amotl pushed a commit to daq-tools/pycom-micropython that referenced this issue Mar 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants