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
Unix port: `uasyncio` does not have certain classes/methods
The uasyncio library does not have the ThreadSafeFlag, Lock and possibly other classes (I haven't checked the rest), and the gather method does not work either. I get the following errors when running on release 1.18:
MicroPython v1.18 on 2022-04-29; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import uasyncio as asyncio
>>> asyncio.ThreadSafeFlag
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "uasyncio/__init__.py", line 26, in __getattr__
AttributeError: ThreadSafeFlag
>>> asyncio.gather
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "uasyncio/__init__.py", line 27, in __getattr__
ImportError: no module named 'uasyncio.funcs'
>>> asyncio.Lock
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "uasyncio/__init__.py", line 27, in __getattr__
ImportError: no module named 'uasyncio.lock'
>>> asyncio.__version__
(3, 0, 0)
I'm not sure whether this is related, but when creating the Unix port with the release zip, I couldn't run make submodules as it wasn't a git directory. When I tried to build from the master branch, I couldn't import uasyncio as it said the .mpy versions were incompatible.