extmod/modselect: Handle pending events before entering poll.

This allows tests like `asyncio_event_queue.py` to succeed under the native
emitter when poll is enabled.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This commit is contained in:
Jeff Epler
2025-11-27 20:40:47 -06:00
committed by Damien George
parent 8248d11806
commit 2782d4598d
3 changed files with 10 additions and 1 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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 (;;) {