diff --git a/unix/modtime.c b/unix/modtime.c index 4a15f1a392..5d59294f2e 100644 --- a/unix/modtime.c +++ b/unix/modtime.c @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -32,6 +33,7 @@ #include "py/runtime.h" #include "py/smallint.h" +#include "py/mphal.h" #ifdef _WIN32 void msec_sleep_tv(struct timeval *tv) { @@ -113,8 +115,23 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) { double ipart; tv.tv_usec = round(modf(val, &ipart) * 1000000); tv.tv_sec = ipart; - sleep_select(0, NULL, NULL, NULL, &tv); + int res; + while (1) { + res = sleep_select(0, NULL, NULL, NULL, &tv); + #if MICROPY_SELECT_REMAINING_TIME + // TODO: This assumes Linux behavior of modifying tv to the remaining + // time. + if (res != -1 || errno != EINTR) { + break; + } + //printf("select: EINTR: %ld:%ld\n", tv.tv_sec, tv.tv_usec); + #else + break; + #endif + } + RAISE_ERRNO(res, errno); #else + // TODO: Handle EINTR sleep(mp_obj_get_int(arg)); #endif return mp_const_none; diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index 8ff4e096d0..740bb9c5d0 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -205,6 +205,10 @@ void mp_unix_mark_exec(void); #define MICROPY_PLAT_DEV_MEM (1) #endif +// Assume that select() call, interrupted with a signal, and erroring +// with EINTR, updates remaining timeout value. +#define MICROPY_SELECT_REMAINING_TIME (1) + #ifdef __ANDROID__ #include #if __ANDROID_API__ < 4