ports/unix: uasyncio.ThreadSafeFlag appears broken
The minimal program to reproduce the issue:
import uasyncio as asyncio
f = asyncio.ThreadSafeFlag()
async def main():
await f.wait()
asyncio.run(main())
The result:
Traceback (most recent call last):
File "t.py", line 8, in <module>
File "/usr/lib/micropython/uasyncio/core.py", line 222, in run
File "/usr/lib/micropython/uasyncio/core.py", line 191, in run_until_complete
File "/usr/lib/micropython/uasyncio/core.py", line 176, in run_until_complete
File "t.py", line 6, in main
File "/usr/lib/micropython/uasyncio/event.py", line 57, in wait
File "/usr/lib/micropython/uasyncio/core.py", line 94, in queue_read
File "/usr/lib/micropython/uasyncio/core.py", line 79, in _enqueue
TypeError: can't convert NoneType to int
I poked around it a bit, and the flow to the failure is as follows:
https://github.com/micropython/micropython/blob/cb99ca9862827f57c370555841810e98701ecfa2/extmod/uasyncio/core.py#L79
https://github.com/micropython/micropython/blob/cb99ca9862827f57c370555841810e98701ecfa2/ports/unix/moduselect.c#L88
https://github.com/micropython/micropython/blob/cb99ca9862827f57c370555841810e98701ecfa2/ports/unix/moduselect.c#L76
This ends up in ThreadSafeFlag.ioctl(), which returns None for any request other than MP_STREAM_POLL and causes the exception above.
https://github.com/micropython/micropython/blob/cb99ca9862827f57c370555841810e98701ecfa2/extmod/uasyncio/event.py#L47-L50
uasyncio ThreadSafeFlag re-entry
Please see my post on the forums:
https://forum.micropython.org/viewtopic.php?f=2&t=11393
I think I've found a bug in the behavior of uasyncio's ThreadSafeFlag which causes program execution to stop if a thread safe flag gets set more than once without being waited upon first
port: ESP32
uasyncio: v3 (using built-in from upy commit f4c1389fb)