From baf75e21d30d38c4ebad16ff1f7d83807431b57c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 27 Nov 2025 19:40:51 -0600 Subject: [PATCH] docs/library: Document that sleep(0)/sleep_ms(0) run the scheduler. Signed-off-by: Jeff Epler --- docs/library/micropython.rst | 4 ++++ docs/library/time.rst | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/docs/library/micropython.rst b/docs/library/micropython.rst index 4d5a064a7a..b9e910ca26 100644 --- a/docs/library/micropython.rst +++ b/docs/library/micropython.rst @@ -130,6 +130,10 @@ Functions a critical region but they will not be executed until that region is exited. An example of a critical region is a preempting interrupt 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, + will call scheduled functions. A use for this function is to schedule a callback from a preempting IRQ. Such an IRQ puts restrictions on the code that runs in the IRQ (for example diff --git a/docs/library/time.rst b/docs/library/time.rst index b53bb133ec..8f413fca92 100644 --- a/docs/library/time.rst +++ b/docs/library/time.rst @@ -71,6 +71,9 @@ Functions other boards may not accept a floating-point argument, for compatibility with them use `sleep_ms()` and `sleep_us()` functions. + Calling ``sleep``, including ``sleep(0)`` is guaranteed to call pending callback + functions. + .. function:: sleep_ms(ms) Delay for given number of milliseconds, should be positive or 0. @@ -80,6 +83,9 @@ Functions interrupt handlers or other threads. Passing in 0 for *ms* will still allow this other processing to occur. Use `sleep_us()` for more precise delays. + Calling ``sleep_ms``, including ``sleep_ms(0)`` is guaranteed to call + pending callback functions. + .. function:: sleep_us(us) Delay for given number of microseconds, should be positive or 0.