Hi
I am running on: MicroPython v1.14-56-g5cb91afb9 on 2021-02-17; PYBD-SF6W with STM32F767IIK
and the below prints False. Any ideas how to get this working?
import uasyncio
l = uasyncio.Lock()
l.acquire()
print("locked ", l.locked())
Device path COM10
Quit: Ctrl+] | Stop program: Ctrl+C | Reset: Ctrl+D
Type 'help()' (without the quotes) then press ENTER.
locked False
MicroPython v1.14-56-g5cb91afb9 on 2021-02-17; PYBD-SF6W with STM32F767IIK
Type "help()" for more information.
>>>
>>>
>>>
uasyncio lock not working
Re: uasyncio lock not working
You need to use lock within an asyncio-based program.
In this case, the acquire method on Lock is a coroutine, i.e. you need to "await" it.
So:
Code: Select all
import uasyncio as asyncio
lock = asyncio.Lock()
async def my_task():
await lock.acquire()
print("locked", lock.locked())
asyncio.run(my_task())
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact: