mirror of
https://github.com/micropython/micropython.git
synced 2026-01-28 06:40:19 +01:00
unix/modtime: Handle pending events during sleep(0).
This ensures that zero-duration sleeps run scheduled callbacks. Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
committed by
Damien George
parent
cfaba3211c
commit
16ccf55fd8
@@ -95,6 +95,7 @@ static mp_obj_t mp_time_sleep(mp_obj_t arg) {
|
||||
tv.tv_sec = (suseconds_t)ipart;
|
||||
int res;
|
||||
while (1) {
|
||||
mp_handle_pending(true);
|
||||
MP_THREAD_GIL_EXIT();
|
||||
res = sleep_select(0, NULL, NULL, NULL, &tv);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
@@ -104,7 +105,6 @@ static mp_obj_t mp_time_sleep(mp_obj_t arg) {
|
||||
if (res != -1 || errno != EINTR) {
|
||||
break;
|
||||
}
|
||||
mp_handle_pending(true);
|
||||
// printf("select: EINTR: %ld:%ld\n", tv.tv_sec, tv.tv_usec);
|
||||
#else
|
||||
break;
|
||||
@@ -114,13 +114,13 @@ static mp_obj_t mp_time_sleep(mp_obj_t arg) {
|
||||
#else
|
||||
int seconds = mp_obj_get_int(arg);
|
||||
for (;;) {
|
||||
mp_handle_pending(true);
|
||||
MP_THREAD_GIL_EXIT();
|
||||
seconds = sleep(seconds);
|
||||
MP_THREAD_GIL_ENTER();
|
||||
if (seconds == 0) {
|
||||
break;
|
||||
}
|
||||
mp_handle_pending(true);
|
||||
}
|
||||
#endif
|
||||
return mp_const_none;
|
||||
|
||||
Reference in New Issue
Block a user