LED staying on with asyncio #16016
-
My program
The output looks correct (ends with a "-OFF" message)
But the LED is staying on about 50% of the time. If I explicitly do a Thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
On further investigation it appears that some of the |
Beta Was this translation helpful? Give feedback.
-
Created issue for this |
Beta Was this translation helpful? Give feedback.
-
I have no definitive answer, but if I was trying to debug this, I would try changing the 5ms delay before turning off the LED to 100 ms ( or more) in case there is some timing or race condition. Asyncio granularity isn't well suited to precise timing at the ms level. |
Beta Was this translation helpful? Give feedback.
-
If I run this code in Thonny (rp2040 pico) with led 5ms on, I always get 5 blinks and the led is always off when the program is finished |
Beta Was this translation helpful? Give feedback.
-
Thanks for trying this everyone. Some additional information:
and copy-pasting the script
but didn't see the problem.
The only thing I can imagine is there was some odd cruft between runs using the Perhaps there were old coroutines kicking around? I'll continue to try to get faithful reproduction steps. |
Beta Was this translation helpful? Give feedback.
This seems the most likely cause: each time you run without reset you are creating a new event/task pair and there may be some code path where the old tasks persist (eg. if they did hit the timeout, then they may remain active as tasks, not 100% sure of the implementation internals here) and so are run by the event loop the next time you start it up alongside your new code.
This is a difference between Micropython and Python - Python Asyncio requires you to keep a reference to a Task while it is running and only uses weakrefs to the Tasks internally.