← index #7965Issue #7978
Related · high · value 0.137
QUERY · ISSUE

ports/unix: uasyncio.ThreadSafeFlag appears broken

openby crzcrzopened 2021-11-03updated 2026-03-23
extmodport-unixproposed-close

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

CANDIDATE · ISSUE

uasyncio ThreadSafeFlag re-entry

closedby oclykeopened 2021-11-05updated 2021-11-06

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)

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