_thread vs uasyncio
-
Hello there,
My project needs multithreading, and some kind of locks.
As far as I know _thread is not support any kind of locks.
So do you know a workaround of that?
uasyncio could be one, but it is not supported on pycom boards. Is there a way to use it?
Which path should I choose?
-
@peterp Note that the 'event.py' which defines a semaphore for asyncio does not load on the latest version, as it depends (for ThreadSafeFlag) on being able to extend uio.IOBase. This base class is not used in the pycom micropython uio port apparently...
This is an issue to use asyncio on pycom ports as ThreadSafeFlag is the only way to do a semaphore from an ISR or other _thread task...any ideas?
-
FWIW, I just made a really short test, took the folder from https://github.com/micropython/micropython/tree/master/extmod/uasyncio and ran their simple 'hello world' example. that worked ok. Haven't tested deeper.
import uasyncio async def blink(led, period_ms): while True: print(led, 'on') await uasyncio.sleep_ms(5) print(led, 'off') await uasyncio.sleep_ms(period_ms) async def main(led1, led2): uasyncio.create_task(blink(led1, 700)) uasyncio.create_task(blink(led2, 400)) await uasyncio.sleep_ms(10_000) uasyncio.run(main(4,5))
I tested on 1.20.3.b3
-
@robert-hh I have downloaded, and updated firmware and confirm it works!
Thanks for you awesome support!
-
@JSmith I have a working subset which is good for 1.20.2.r4. Part of that is from micropython-lib/uasyncio in a maybe older version. https://github.com/micropython/micropython-lib.
I did not use that a lot, but what I appended works. So it may be a starting point. I could not add an archive here, so you'll find it here: https://github.com/robert-hh/Shared-Stuff/blob/master/uasyncio.zip
-
@robert-hh thank you very much for the insight.
Is V2 the version that was supposed to be supported in: https://forum.pycom.io/topic/3480/new-firmware-development-release-v1-19-0-b4 ?
I suppose what I am trying to understand is if there is anyway I can get a version of uasyncio working on my Wipy3.0?
-
@JSmith Uasyncio V3 is not supported. The Pycom firmware still sticks to an old version of the MicroPython core, and even for uasyncio V2 there is a pitfall, which is the order of arguments of ticks_diff.
-
Hi guys, this topic is similar to my current issue.
I see uasyncio was supposed to be supported as per: https://forum.pycom.io/topic/3480/new-firmware-development-release-v1-19-0-b4/15
This would be brilliant for my scheduling requirements, and since I am running firmware: 1.20.2.r2 I attempted to use this using upip install, as per: https://medium.com/@chrismisztur/pycom-uasyncio-installation-94931fc71283
However I cannot seem to use the library as I get error: "AttributeError: 'module' object has no attribute 'run'" if I try and run any of the tutorial code.
I assume the pip install has installed V3 uasyncio. Is this supported? Or could anyone help point me at direction for installing uasyncio?
Kind regards, Jake
-
@livius That is new. Least for me. I haven't use pycom boards for a year now. Thanks! :)
-
@tttadam said in _thread vs uasyncio:
As far as I know _thread is not support any kind of locks.
What about this?
https://docs.pycom.io/firmwareapi/micropython/_thread/#class-lock