docs: Add notes on heap allocation caused by bound method refs.

This commit is contained in:
Peter Hinch
2017-11-12 06:13:45 +00:00
committed by Damien George
parent df078e8213
commit ec1e9a10a7
2 changed files with 39 additions and 1 deletions

View File

@@ -112,5 +112,14 @@ Functions
the heap may be locked) and scheduling a function to call later will lift
those restrictions.
There is a finite stack to hold the scheduled functions and `schedule`
Note: If `schedule()` is called from a preempting IRQ, when memory
allocation is not allowed and the callback to be passed to `schedule()` is
a bound method, passing this directly will fail. This is because creating a
reference to a bound method causes memory allocation. A solution is to
create a reference to the method in the class constructor and to pass that
reference to `schedule()`. This is discussed in detail here
:ref:`reference documentation <isr_rules>` under "Creation of Python
objects".
There is a finite stack to hold the scheduled functions and `schedule()`
will raise a `RuntimeError` if the stack is full.