← index #5795Issue #5843
Related · high · value 4.184
QUERY · ISSUE

extmod/uasyncio Event.set() not safe in ISR

openby kevinkk525opened 2020-03-25updated 2020-04-07
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

extmod/uasyncio: Loop exits if only Tasks awaiting Events are added

openby kevinkk525opened 2020-03-30updated 2021-02-18
extmod

If only Tasks are added to the Loop that are waiting for an Event to be set (or a Lock to be acquired but that makes no sense at all), the loop exits because those Tasks get removed from the main queue and put onto the waiting queue of the Event.
Use-case: Event is waiting to be set from an ISR. Will probably only ever be used without other Tasks running in minimal test-cases but would then be a problematic bug.

Expected behaviour: Loop continues to run. This needs #5795 (Events from ISR). Otherwise this problem will of course never occur.

>>> import uasyncio as asyncio
>>> ev=asyncio.Event()
>>> async def wait():
...     print("started waiting")
...     await ev.wait()
...     print("got event")
...
...
...
>>> asyncio.run(wait())
started waiting
>>>

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied