Skip to content

Commit 2782d45

Browse files
jeplerdpgeorge
authored andcommitted
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>
1 parent 8248d11 commit 2782d45

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

docs/library/micropython.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ Functions
132132
handler (an IRQ).
133133
- Inside native code functions, scheduled functions are not called unless
134134
the native code calls a function that specifically does so.
135-
- ``time.sleep`` and ``time.sleep_ms``, including zero-duration sleeps,
135+
- Certain functions including ``poll.poll``, ``poll.ipoll``,
136+
``time.sleep`` and ``time.sleep_ms`` (including zero-duration sleeps)
136137
will call scheduled functions.
137138

138139
A use for this function is to schedule a callback from a preempting IRQ.

docs/library/select.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Methods
7676

7777
In case of timeout, an empty list is returned.
7878

79+
Calling ``poll.poll`` is guaranteed to call pending callback functions
80+
before entering the polling loop.
81+
7982
.. admonition:: Difference to CPython
8083
:class: attention
8184

@@ -93,6 +96,9 @@ Methods
9396
won't be processed until new mask is set with `poll.modify()`. This
9497
behaviour is useful for asynchronous I/O schedulers.
9598

99+
Calling ``poll.ipoll`` is guaranteed to call pending callback functions
100+
before entering the polling loop.
101+
96102
.. admonition:: Difference to CPython
97103
:class: attention
98104

extmod/modselect.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ static mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size
342342
mp_uint_t start_ticks = mp_hal_ticks_ms();
343343
bool has_timeout = timeout != (mp_uint_t)-1;
344344

345+
mp_handle_pending(true);
346+
345347
#if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS
346348

347349
for (;;) {

0 commit comments

Comments
 (0)