Skip to content
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

utime.sleep_ms does nothing useful when called with 0 milliseconds. #5345

Closed
nevercast opened this issue Nov 20, 2019 · 2 comments
Closed

utime.sleep_ms does nothing useful when called with 0 milliseconds. #5345

nevercast opened this issue Nov 20, 2019 · 2 comments
Labels

Comments

@nevercast
Copy link
Contributor

While debugging #5344 I encounted a situation where utime.sleep_ms(0) did not free the GIL to another thread. This is because utime.sleep_ms(0) is a useless invocation that does nothing.

if (ms > 0) {

STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) {
    mp_int_t ms = mp_obj_get_int(arg);
    if (ms > 0) {
        mp_hal_delay_ms(ms);
    }
    return mp_const_none;
}

I propose that at the very least this function calls MICROPY_EVENT_POLL_HOOK when ms is zero, and at best, always calls mp_hal_delay_ms. I don't believe zero should be a special case.

@dpgeorge
Copy link
Member

I don't believe zero should be a special case.

I agree. It should have "continuous" behaviour for sleep_ms(x) where x tends to 0.

dpgeorge pushed a commit that referenced this issue Jul 21, 2021
This makes sleep_ms(0) useful as a "yield" so event processing and thread
switching can take place.

Fixes issue #5345.
@dpgeorge
Copy link
Member

Fixed by db6d60b

tannewt pushed a commit to tannewt/circuitpython that referenced this issue Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants