diff --git a/docs/library/micropython.rst b/docs/library/micropython.rst index b9e910ca26..2da9a6e3fd 100644 --- a/docs/library/micropython.rst +++ b/docs/library/micropython.rst @@ -132,7 +132,8 @@ Functions handler (an IRQ). - Inside native code functions, scheduled functions are not called unless the native code calls a function that specifically does so. - - ``time.sleep`` and ``time.sleep_ms``, including zero-duration sleeps, + - Certain functions including ``poll.poll``, ``poll.ipoll``, + ``time.sleep`` and ``time.sleep_ms`` (including zero-duration sleeps) will call scheduled functions. A use for this function is to schedule a callback from a preempting IRQ. diff --git a/docs/library/select.rst b/docs/library/select.rst index 57adbb49af..6df1ff9c23 100644 --- a/docs/library/select.rst +++ b/docs/library/select.rst @@ -76,6 +76,9 @@ Methods In case of timeout, an empty list is returned. + Calling ``poll.poll`` is guaranteed to call pending callback functions + before entering the polling loop. + .. admonition:: Difference to CPython :class: attention @@ -93,6 +96,9 @@ Methods won't be processed until new mask is set with `poll.modify()`. This behaviour is useful for asynchronous I/O schedulers. + Calling ``poll.ipoll`` is guaranteed to call pending callback functions + before entering the polling loop. + .. admonition:: Difference to CPython :class: attention diff --git a/extmod/modselect.c b/extmod/modselect.c index d06157e585..229f8f737b 100644 --- a/extmod/modselect.c +++ b/extmod/modselect.c @@ -342,6 +342,8 @@ static mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size mp_uint_t start_ticks = mp_hal_ticks_ms(); bool has_timeout = timeout != (mp_uint_t)-1; + mp_handle_pending(true); + #if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS for (;;) {