Closed rbedia closed 2 years ago
@tekktrik can you take a look at this? The change appears to have been introduced by a PR about "add docstrings" which is odd. https://github.com/adafruit/Adafruit_CircuitPython_asyncio/pull/19/files#diff-6c3d301ce3f21e806072e5b6da07862be0327e8fb5245117013252c725224348R72
Based on a quick read, "yield" in the context of cp/mp asyncio seems to mean "don't schedule me ever, something else will manually schedule me" while "await asyncio.sleep(0)" means "reschedule me as soon as possible". However, I think that's not CPython compatible; yield in an async def is a way of writing an async generator, since python 3.6: https://stackoverflow.com/questions/37549846/how-to-use-yield-inside-async-function
I'll take a look. The change was made to help get the linter pass, or something like that.
If it needs to be changed back, I didn't have any reason of my own to change them as I did.
I had to change several yield
inside the asyncio library to asyncio.sleep(0)
when I was proting it
I think they have different semantics in Circuit/MicroPython.
Closed by #30
asyncio.Lock() is not preventing concurrent acquiring of the lock.
Circuitpython version: Adafruit CircuitPython 7.3.3 on 2022-08-29; Adafruit Feather Bluefruit Sense with nRF52840
main.py:
Output:
When
await core.sleep(0)
is used inacquire()
, task B is able to acquire the lock even though task A has not yet released the lock. This then leads to the exception when B tries to release the lock that was already released by A.As a test I modified
asyncio/lock.py
to show that going back to usingyield
works while usingawait core.sleep(0)
does not.