Creating an asyncio task from within an interrupt handler? #11087
Replies: 3 comments 4 replies
-
Did a quick test and checked free memory from within the callback
And the output is:
Does this mean that creating a task does indeed allocate memory and I should avoid what I am doing? Is there a way to use a pre-existing task and just set it to run from within the callback? |
Beta Was this translation helpful? Give feedback.
-
Is this the better way to do it then?
Seems to work ok - but bit more convoluted so if I can just create tasks from within the callback that would be ideal but if not I'm happy to use this. Nice thing about this is it pretty much has built-in debouncing. |
Beta Was this translation helpful? Give feedback.
-
There are subtle hazards in creating a task in a callback. I suggest you read this doc which goes into interfacing interrupts with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following code where I create an asyncio task from within the interrupt handler callback
And the output is as below if I press the button once (not debounced)
However the micropython documentation suggests that I should avoid memory allocation from within the interrupt handler.
Avoid memory allocation: no appending to lists or insertion into dictionaries, no floating point.
Does creating an asyncio task allocate memory? Should I avoid what I'm doing here?
Beta Was this translation helpful? Give feedback.
All reactions