QUERY · ISSUE
extmod/uasyncio Event.set() not safe in ISR
extmod
If you call Event.set() in an ISR, you could end up losing all tasks that were awaiting the event (if the ISR is executed while uasyncio is sorting tasks on the queue e.g.).
I made a testscript a while ago to demonstrate this: https://gist.github.com/kevinkk525/5b89395604da3df3be7a015abcba04fa
CANDIDATE · ISSUE
uasyncio Event unexpected behaviour with only one task
[EDIT] Apologies, @kevinkk525 has pointed out that this is a duplcate of https://github.com/micropython/micropython/issues/5843
This prints "start" then runs to completion where I would expect it to wait indefinitely on the Event:
import uasyncio as asyncio
evt = asyncio.Event()
async def main_loop():
while True:
print("start")
await evt.wait()
await asyncio.sleep(1)
print("Got event")
asyncio.run(main_loop())
If an additional task is running the main_loop task behaves as expected, waiting forever:
import uasyncio as asyncio
evt = asyncio.Event()
async def main_loop():
while True:
print("start")
await evt.wait()
await asyncio.sleep(1)
print("Got event")
async def main():
asyncio.create_task(main_loop())
while True:
await asyncio.sleep(1)
asyncio.run(main())